English 中文(简体)
shouldAutorotateToInterfaceOrientation:过一段时间后无法调用
原标题:shouldAutorotateToInterfaceOrientation: fails to get called after a while

我有一个项目,在删除/添加大量视图/视图控制器后,旋转事件停止启动。它工作了一段时间,然后随机添加到窗口的新视图永远不会得到shouldAutorotateToInterfaceOrientation:调用。

状态栏也无法旋转,但视图/视图控制器功能正常(减去旋转)。此外,一次只有一个视图/viewController添加到窗口中。我假设一个旧的viewController被注册为键,但添加到窗口的所有东西都是viewController的子类,并且除了活动的子类之外,没有任何子类显示在仪器分配中。

有没有办法在应用程序代理或窗口上找到哪个视图控制器是关键?

是否有其他原因导致shouldAutorotateToInterfaceOrientation:无法被调用?

每个视图控制器都在实现:

- (BOOL)shouldAutorotateToInterfaceOrientation:

(UIInterfaceOrientation)interfaceOrientation { return YES; }

- (void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation) 
                     interfaceOrientation duration: (NSTimeInterval) duration {
    //manual rotation code
}

以下是我在应用程序委托中使用的代码,用于更改根视图控制器和显示的视图。

[UIView transitionWithView:new.view 
                  duration:0.3
                   options:UIViewAnimationOptionCurveEaseOut
                animations:^{
                    //add new view
                    [self.window addSubview:new.view];

                    //play transition animation for old and new views
                    new.view.transform = CGAffineTransformConcat(new.view.transform, newEnd);
                    old.view.transform = CGAffineTransformConcat(old.view.transform, oldEnd);

                    //if old view is a "modal style" then keep it in front on new view
                    if([old conformsToProtocol:@protocol(PreloadableModalView)]) {
                        [self.window bringSubviewToFront:old.view];
                    }

                }
                completion:^(BOOL finished){
                    //remove old view
                    [old removeSubviews];
                    [old.view removeFromSuperview];
                }];
最佳回答

问题的根源似乎是删除了窗口在转换期间发送旋转事件的viewController,导致窗口有时不会将新的viewController注册为新的根。

我只在窗口中添加了一个UIView(带有自己的UIViewController)。在动画制作过程中,我删除了根视图控制器,并在屏幕上添加了一个新的控制器。修复方法是在动画之前切换视图控制器。

  1. 我创建了当前视图的屏幕截图

  2. 删除了旧的视图控制器

  3. 将新的视图控制器设置为rootviewcontroller,并将视图添加到窗口中

  4. 运行过渡动画

  5. 完成后我删除图像

这是代码的主要部分:

//create a image of old view and add to window
UIGraphicsBeginImageContext(old.view.bounds.size);
[[old.view layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *screenshot = [[UIImageView alloc] initWithImage:snapshot];
[self.window addSubview:screenshot];
[screenshot release];

//remove view and viewcontroller
[old.view removeFromSuperview];

//set new viewcontroller as root
if(self.window.rootViewController)
    self.window.rootViewController = nil;
self.window.rootViewController = new;

//transition code goes here


//animate
[UIView transitionWithView:new.view 
                  duration:0.5
                   options:UIViewAnimationOptionCurveEaseOut
                animations:^{

                    //add new view
                    [self.window addSubview:new.view];

                    //play transition animation
                    if(isOldModalDisplay) {
                        screenshot.transform = CGAffineTransformConcat(new.view.transform, newEnd);
                        [self.window bringSubviewToFront:screenshot];
                    } else {
                        new.view.transform = CGAffineTransformConcat(new.view.transform, newEnd);
                    }
                }
                completion:^(BOOL finished){
                    //remove screenshot
                    [screenshot removeFromSuperview];
                }];
问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签