我是新手,如果这是一个愚蠢的疑问,请原谅我...我最近将我的项目从xcode3更改为xcode4,现在出现了一些问题,我不知道为什么...
为了管理我的滚动视图的框架和内容大小,以及如果方向改变它的变化,我有这个:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
scrollView.frame = CGRectMake(0,0,480,300);
[scrollView setContentSize:CGSizeMake(480,560)];
}
else {
scrollView.frame = CGRectMake(0,0,320,460);
[scrollView setContentSize:CGSizeMake(320,560)];
}
[scrollView flashScrollIndicators];}
我认为使用 Xcode3,应用程序在加载屏幕时调用此方法,因此它在任何情况下都能完美运行。
但在 Xcode4 中,应用程序在屏幕加载时不会调用此方法。它只在方向改变时调用它(我不知道为什么存在这种差异)。因此,加载屏幕时,我的滚动视图不起作用。只有当我改变设备的方向时它才开始工作。
然后,我尝试了这个:
- (void)viewDidLoad {
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft ||
[[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
scrollView.frame = CGRectMake(0,0,480,300);
[scrollView setContentSize:CGSizeMake(480,560)];
}
else {
scrollView.frame = CGRectMake(0,0,320,460);
[scrollView setContentSize:CGSizeMake(320,560)];
}
[scrollView flashScrollIndicators];
[super viewDidLoad];}
它显然正在工作,但是......发生了一些非常奇怪的事情......
如果我转到另一个视图(纵向),然后将方向更改为横向,然后返回第一个视图(横向),视图的自动调整大小蒙版会变得疯狂。所有内容都移到右侧,就好像视图的宽度比实际宽度大。而且我无法访问部分内容。但是,如果现在我将方向更改为纵向,即使我再次转到横向,一切都会再次正常。所以,只有当我从另一个横向视图中看到视图时,它才是错误的。
这就是我从一个视图传递到另一个视图的方式:
- (IBAction) btnUnVano:(id) sender {
PE2100UnVano *controller = [[PE2100UnVano alloc] initWithNibName:@"PE2100UnVano" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
[controller release];}
我该怎么办?
Pd:对不起我的英语
编辑
好的,这部分现在已经修复了。我删除了 willAnimateRotationToInterfaceOrientation,现在它可以正常工作了:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Si la orientación es horizontal..
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft ||
[[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
scrollView.frame = CGRectMake(0,0,480,300);
[scrollView setContentSize:CGSizeMake(480,560)];
}
// Si la orientación es vertical..
else {
scrollView.frame = CGRectMake(0,0,320,460);
[scrollView setContentSize:CGSizeMake(320,560)];
}
// Mostrar durante un instante los indicadores de scroll
[scrollView flashScrollIndicators];
// Retorna YES para soportar todas las orientaciones posibles
return YES;}
现在,还有另一个问题。在某些屏幕中,我使用以下代码返回上一个屏幕:
- (IBAction) btnAtrasTabla:(id) sender {
[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];}
在这种情况下,自动调整大小的问题再次出现。我在纵向上转到此屏幕,然后更改为横向,然后返回上一个,并且上一个出现错误的自动调整大小。然后,我改变方向,一切又是正确的......有什么想法吗?