更改iPadd应用的方向时遇到一些问题。
我写了一个函数,可以设置我的子视图,以便在视图出现或旋转时调用它。
当“viewWillAppear”函数调用该函数时,该函数可以很好地工作。但是,当“willAnimateRotationToInterfaceOrientation”函数调用我的布局功能(“setPositionsForOrientation”)我现在面临以下问题:在iPad上更改方向后错误定位
- 当从纵向改为横向我有一个128像素左侧
- 偏移时更改风景人像我有一个负左侧
在我的印象偏移,莫明的新的帧的属性没有被正确处理,因为我的UIScrollViews也应该调整,但他们没有这样做。
这是我的代码中写道:
- (void)viewWillAppear:(BOOL)animated{
[self setPositionsForOrientation:self.interfaceOrientation];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)newInterfaceOrientation duration:(NSTimeInterval)duration {
[self setPositionsForOrientation:newInterfaceOrientation];
}
- (void)setPositionsForOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Position the UI elements for landscape mode
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
self.view.frame = CGRectMake(0, 0, 1024, 748);
self.menubarImage.frame = CGRectMake(0, 0, 1024, 121);
self.backgroundImage.frame = CGRectMake(0, 0, 1024, 748);
self.mainCategories.frame = CGRectMake(6, 6, 1012, 55);
self.subCategories.frame = CGRectMake(58, 79, 960, 30);
self.moviesContainer.frame = CGRectMake(6, 204, 1012, 456);
self.searchButton.frame = CGRectMake(935, 709, 80, 30);
}
// Position the UI elements for portrait mode
else {
self.view.frame = CGRectMake(0, 0, 768, 1004);
self.menubarImage.frame = CGRectMake(0, 256, 768, 121);
self.toolbarImage.frame = CGRectMake(0, 924, 768, 80);
self.backgroundImage.frame = CGRectMake(0, 256, 768, 748);
self.mainCategories.frame = CGRectMake(6, 262, 756, 55);
self.subCategories.frame = CGRectMake(58, 335, 704, 30);
self.moviesContainer.frame = CGRectMake(6, 460, 756, 456);
self.searchButton.frame = CGRectMake(680, 963, 80, 30);
}
}
这里有一些图片来说明我的问题..
布局IB(所有子视图都contentMode设置为左上角)
http://www.abload.de/image.php?img=interfacebuilderl9ey.png
肖像模式显示正确/奇怪
http://www.abload.de/image.php?img=portrait_oklxf1.png
http://www.abload.de/image.php?img=portrait_failma8y.png
正确/奇怪
http://www.abload.de/image.php?img=landscape_ok4z2l.png
http://www.abload.de/image.php?img=landscape_failvzuy.png
我做了什么错,更重要的是,我怎么能解决它显示
风景模式?
我发现this帖子里面介绍了常用的方式,但我不明白我怎么可以重写我的意见“layoutSubviews”的方法,因为视图仅仅是我的UIViewController财产..
我做的一切你告诉我,感动了所有实例变量和属性,以新的视图类。 但是,对于所有属性,我都会收到错误“请求会员不属于结构或联盟”。 如果我用我的新类重新声明视图控制器中的视图属性,但是然后我得到警告“属性”视图“类型不符合超类'UIViewController'属性类型”,并且应用程序崩溃时,此错误消失显示控制器。 :( –
2011-01-17 10:56:27