我创建了一个UIViewController,它以编程方式生成UIScrollView。一切都很好,但是当我旋转设备时,UIScollView应调整大小,以便占用视图的整个宽度。
有没有办法在不重建完整的UIScrollView的情况下做到这一点?
很多! 塞巴斯蒂安
这在我的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中调用了该方法...因为我不知道还有什么地方可以调用它。
再次感谢!!
答案 0 :(得分:2)
[scrollView setFrame:CGRectmake(x,y,width,height)]; //也许您需要对scrollView的内容执行相同的操作以使其适合您的布局
应该这样做。如果需要进行转换,可以将其包装在UIAnimation块中。
答案 1 :(得分:0)
试试这个:
if(self.rowNumber == 0){
/******************* Scroller Setup *****************/
// how many pages
int pageCount = 5;
//set up the scrollView
UIScrollView *scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 960)];
// support for Landscape Orienation
if(UIInterfaceOrientationLandscapeLeft){
[scroller setFrame:CGRectMake(0,0,1024, 704)];
}
if(UIInterfaceOrientationLandscapeRight){
[scroller setFrame:CGRectMake(0,0,1024, 704)];
}