0

我正在尝试配置我的一种观点。我可以正确设置尺寸,但是当我添加自动调整蒙版时,它会立即改变尺寸。

- (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 面具。滚动视图和带有掩码的标签栏之间有一个很大的白色部分。为什么会这样?我该如何解决?

4

1 回答 1

0

您不需要考虑导航和标签栏。

尝试这个。当您初始化滚动视图时,您将其设置为调整大小之前的视图大小,并且一旦加载您的视图,您的视图将自动调整视图大小。

- (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];

}
于 2013-06-12T05:23:38.510 回答