gpt4 book ai didi

iphone - 横向模式下的 UIScrollView 框架大小问题

转载 作者:行者123 更新时间:2023-12-03 20:59:08 27 4
gpt4 key购买 nike

我正在尝试使 UIScrollView 自动调整大小并在横向模式下正确显示。肖像模式效果很好。这是我的代码:

- (void)viewDidLoad {
[super viewDidLoad];

//=== load all the custom view
NSMutableArray *controllers = [[NSMutableArray alloc] init];

int page = 0;
[controllers addObject:[self loadScrollView:[[Page1ViewController alloc] initWithNibName:@"Page1ViewController" bundle:nil] withPage:page++]];
[controllers addObject:[self loadScrollView:[[Page2ViewController alloc] initWithNibName:@"Page2ViewController" bundle:nil] withPage:page++]];
[controllers addObject:[self loadScrollView:[[Page3ViewController alloc] initWithNibName:@"Page3ViewController" bundle:nil] withPage:page++]];

self.viewControllers = controllers;
[controllers release];
//=== automaticaly define number of pages
_numberOfPages = [self.viewControllers count];

// a page is the width of the scroll view
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * _numberOfPages, scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;

// First, set the number of pages
pageControl.numberOfPages = _numberOfPages;
pageControl.currentPage = 0;

}

然后,我进入每个 View Controller nib 文件并将背景设置为不同的颜色以测试它是否正常工作。不幸的是,在横向模式下,宽度和高度与纵向模式下相同。

我不知道如何解决这个问题。希望任何人都可以帮助我。提前谢谢了。

最佳答案

我遇到了同样的问题,但前提是我在横向模式下打开 View ,而该 View 是在纵向模式的 .xib 中设计的。

如果我以纵向打开,然后旋转设备,它的大小正确。

我发现,如果我在 viewWillAppear 中加载 View Controller 数组,而不是在 viewDidLoad 中,它的大小始终正确。

关于iphone - 横向模式下的 UIScrollView 框架大小问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2450726/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com