Autoresizingmask会立即覆盖最初设置的框架(创建不同的错误布局) [英] Autoresizingmask instantly overrides initially set frame (creating a different and wrong layout)

查看:46
本文介绍了Autoresizingmask会立即覆盖最初设置的框架(创建不同的错误布局)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置我的其中一个视图.我可以正确设置尺寸,但是当我添加自动调整大小蒙版时,它会立即更改尺寸.

I'm trying to configure one of my views. I can set the dimensions properly, but when I add the autoresizing mask it instantly changes the size.

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - self.tabBarController.tabBar.frame.size.height - self.navigationController.navigationBar.frame.size.height - 10)]; // -10 so I know it's not being hidden under the tabbar
    scrollView.backgroundColor = [UIColor greenColor]; // easy recognition
    scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [self.view addSubview: scrollView];
    self.scroll = scrollView;
    UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(hmm)];
    [self.navigationController.navigationBar addGestureRecognizer: tap];

}

- (void) hmm {
    NSLog(@"Frame: %@", [NSValue valueWithCGRect: self.scroll.frame]);
}

我不戴口罩时得到357,而戴口罩时得到264.在滚动视图和带有蒙版的标签栏之间有一个很大的白色部分.为什么会这样呢?我该如何解决?

I get 357 without the mask and 264 with the mask. There's a big white section between the scrollview and tabbar with the mask. Why is it like this? How can I fix it?

推荐答案

您无需考虑导航和标签栏.

You shouldn't need to account for the navigation and tabbar.

尝试一下.初始化scrollview时,要先使其成为视图的大小,然后再重新调整大小,一旦加载,您的视图将自动随该视图调整大小.

Try this. When you are initing the scrollview you are making it the size of the view before re size, and once it loads your view will automatically re size with the view.

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height- 10)]; // -10 so I know it's not being hidden under the tabbar
    scrollView.backgroundColor = [UIColor greenColor]; // easy recognition
    scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [self.view addSubview: scrollView];
    self.scroll = scrollView;
    UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(hmm)];
    [self.navigationController.navigationBar addGestureRecognizer: tap];

}

这篇关于Autoresizingmask会立即覆盖最初设置的框架(创建不同的错误布局)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆