Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone Scrollview在xcode4上不工作(在xcode3上工作)_Iphone_Ios5_Uiscrollview_Xcode3to4 - Fatal编程技术网

Iphone Scrollview在xcode4上不工作(在xcode3上工作)

Iphone Scrollview在xcode4上不工作(在xcode3上工作),iphone,ios5,uiscrollview,xcode3to4,Iphone,Ios5,Uiscrollview,Xcode3to4,我是个新手,所以如果这是一个愚蠢的疑问,请原谅我。。。 我最近将我的项目从xcode3改为xcode4,现在出现了一些问题,我不知道为什么 要管理scrollview的框架和内容大小,以及方向改变时的变化,我有以下功能: - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (

我是个新手,所以如果这是一个愚蠢的疑问,请原谅我。。。 我最近将我的项目从xcode3改为xcode4,现在出现了一些问题,我不知道为什么

要管理scrollview的框架和内容大小,以及方向改变时的变化,我有以下功能:

- (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中,当屏幕加载时,应用程序不会调用此方法。它只在方向改变时调用它(我不知道为什么会存在这种差异)。因此,当屏幕加载时,我的scrollview不工作。当我改变设备的方向时,它才开始工作

然后,我试了一下:

- (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];}
我该怎么办

对不起我的英语


编辑 好的,这部分现在修好了。我删除了WillAnimateRotationInterfaceOrientation,现在它可以正确地处理以下内容:

- (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];}

在这种情况下,自动调整大小的问题再次出现。我在纵向屏幕上转到该屏幕,我切换到横向,我返回到上一个屏幕,上一个屏幕显示错误的自动大小。然后,我改变方向,一切又恢复正常。。。有什么想法吗?

任何viewController.view添加到您的rootViewController会从rootViewController本身继承其行为

[self.view addSubview:anotherViewController.view];
这意味着您只需要在rootViewController中启用shouldAutorotateToInterfaceOrientation

如果将viewController显示为模态视图,则会有不同的行为

[self presentModalViewController:anotherViewController animated:YES];
因此,您需要在父视图和模态视图本身中启用shouldAutorotateToInterfaceOrientation


一个正确的体系结构应该可以解决您的问题,但是如果您无法清理代码,我认为有一个解决方法:检查当前视图中的方向,并向其他视图发送通知,以便设置它们的框架。请记住,此解决方法可能有用,但不推荐使用。

以下是我在Beppe的建议下最后所做的

在“child”视图中,当我离开它时,我会发送一个通知:

[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"resize" object:nil userInfo:nil];
然后,“父”视图就是观察者:

- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shouldAutorotateToInterfaceOrientation:) name:@"resize" object:nil];
[super viewDidLoad];}

这样,当我们从“子”视图返回到“父”视图时,将调用shouldAutorotateToInterfaceOrientation方法。请记住,在这种方法中,我会调整所有内容的大小以适应应用程序的当前方向。

在这种情况下,当您使用presentModalViewController时,您的ViewController会发生更改。因此,将其设置为子视图,而不是显示viewController。查看viewController编程指南。但是我有100多个不同的屏幕。。。我必须生成所有子视图吗?一定有办法解决这个问题。。。我仍然不明白为什么它在iOS4上工作,而现在它不工作了……当我使用此代码返回视图时,是否调用了任何方法?[[self-presentingViewController]解除ViewController激活:是完成:无];我尝试使用addsubview和removesubview,但不起作用。。。添加的视图无法正确响应方向更改。如果我转到风景中添加的那个,它被添加了,但它出现在肖像上。因此,我可以在后面看到横向视图的另一个视图,以及前面添加的垂直视图(但设备是横向的)。尝试一个只有两个视图和所有可能组合的新项目,它应该可以工作…我想我已经修复了它。我明天会发布解决方案(我现在不能发布,我要等8个小时,论坛说:P)。谢谢你的建议,下一个项目我会记住的!正如您所说,当我离开“child”视图时,我只是向通知中心发送一个通知。“父”视图是观察者,当它接收到信号时,它运行shouldAutorotateToInterfaceOrientation方法以正确实现视图。明天我会把密码寄出去:D