Autoresizingmask立即覆盖最初设置的框架(创build一个不同的和错误的布局)
我正在尝试configuration我的一个视图。 我可以正确设置尺寸,但是当我添加自动调整掩码时,它会立即改变尺寸。
- (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面具。 在scrollview和tabbar之间有一个很大的白色区域。 为什么这样? 我该如何解决?
您不需要考虑导航和标签栏。
尝试这个。 当你启动scrollview的时候,你需要在重新resize之前使它成为视图的大小,一旦它加载了你的视图,就会自动重新调整视图的大小。
- (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]; }