我做了一个UIViewController,它以编程方式生成一个UIScrollView。一切都很好,但是当我旋转设备,UIScollView应该调整大小,因此它需要我的视图的完整宽度。Autoresize UIScrollView
有没有办法做到这一点,而不重建完整的UIScrollView?
Thx很多! 塞巴斯蒂安
这就是所谓的在我viewDidLoad中:
-(void)buildmyScroller {
myScroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 800, 768, 100)];
//...adding some subviews to myScroller
thumbScroller.contentSize = CGSizeMake(3000, 100);
[[self view] addSubview:myScroller];
}
然后我试图调整myScroller这一点,当我用SETFRAME,我说myScroller不会对此作出回应...:
-(void)changemyScroller {
UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
[thumbScroller setFrame:CGRectMake(0, 805, 768, 150)];
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
thumbScroller.frame = CGRectMake(0, 805, 768, 150);
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
thumbScroller.frame = CGRectMake(0, 549, 1024, 150);
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
thumbScroller.frame = CGRectMake(0, 549, 1024, 150);
}
}
并在didAnimateFirstHalf中调用该方法...因为我不确定要在哪里调用它。
Thx很多!
非常感谢!解决方案可以很容易:) – wolfrevo 2010-06-14 22:04:59
还有一个问题,我的滚动现在适合我的布局和内容也有正确的大小,但是当我开始在横向(scrollwidth 1024px)和旋转zu肖像(scrollwidth 768px)我不能使用滚轮。当我开始纵向并旋转到横向时,我只能在第一个768像素进行交互,所以在右侧我无法与滚动器交互。当我转到另一个视图时,回到包含scrollview的视图,我可以使用它。所以在显示时不能更改scrollView?或者我应该在哪里改变它?谢谢。 – wolfrevo 2010-06-15 08:52:41
嗨我猜你在loadView或viewDidLoad中设置了你的UIScrollView?也许甚至init? (这意味着只有在调用这些函数时才会更新它)。尝试在viewDidLoad中放置UIScrollView的实例,但是在单独的函数中设置,更改内容和方向。现在,您可以从viewWillAppear和ShouldAutoRotate中调用此函数...因此,您在第一次加载时,旋转时以及转到另一个视图时都会发生此设置。 – RickiG 2010-06-15 12:15:24