【发布时间】:2012-01-31 14:35:48
【问题描述】:
我是新手,如果这是一个愚蠢的疑问,请原谅我...... 最近把我的项目从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];}
在这种情况下,自动调整大小的问题再次出现。我在纵向上转到此屏幕,然后更改为横向,然后返回到上一个,并且上一个出现错误的自动调整大小。然后,我改变了方向,一切又是正确的......有什么想法吗?
【问题讨论】:
-
在这种情况下,当您使用 presentModalViewController 时,您的 ViewController 会发生变化。所以让它成为 subView 而不是呈现 viewController。查看 viewController 编程指南。
-
但是我有 100 多个不同的屏幕...我必须将它们全部设为子视图吗?必须有某种方法来解决这个问题......我仍然不明白为什么这在 iOS4 上工作,现在它不......
-
当我使用此代码返回视图时是否调用了任何方法? [[self presentingViewController]dismissViewControllerAnimated:YES 完成:nil];
标签: iphone ios5 uiscrollview xcode3to4