2011-03-10 45 views
2

我在视图之间切换使用视图动画,其作品,但我有一个接口方向的问题。interfaceorientation保持相同removeFromSuperview并再次addSubview

我在窗口上有两个视图。

  1. authenticationViewCont
  2. mainViewCont

两者有一个按钮,当按钮点击authenticationViewCont我将其删除,并显示mainViewCont,反之亦然。

一旦我addSubview的authenticationViewCont.view并把设备处于纵向模式然后通过removeFromSuperview删除它,然后我在我的手里更改设备方向为横向,然后再addSubview的authenticationViewCont。它首先在肖像中显示动画并在动画之后改变方向。

-(void)mainToAuthentication { 
    CGRect originalFrame = authenticationViewCont.view.frame; 
    CGRect modifiedFrame = originalFrame; 
    modifiedFrame.origin.y = originalFrame.size.height; 
    // made view out from screen 
    authenticationViewCont.view.frame = modifiedFrame; 
    // add sub view on top of other views 
    [self.window addSubview:authenticationViewCont.view]; 
    // transiting view from bottom to center of screen 
    [UIView animateWithDuration:0.5 
     animations:^{ authenticationViewCont.view.frame = originalFrame; } 
     completion:^(BOOL finished){ mainViewCont.view removeFromSuperview; }]; 
} 

-(void)authenticationToMain { 
    CGRect originalFrame = mainViewCont.view.frame; 
    CGRect modifiedFrame = originalFrame; 
    modifiedFrame.origin.y = -originalFrame.size.height; 
    // made view out from screen 
    mainViewCont.view.frame = modifiedFrame; 
    // add sub view on top of other views 
    [self.window addSubview:mainViewCont.view]; 
    // transiting view from top to center of screen 
    [UIView animateWithDuration:0.5 
     animations:^{ mainViewCont.view.frame = originalFrame; } 
     completion:^(BOOL finished){ authenticationViewCont.view removeFromSuperview; }]; 
} 

我怎样才能使其在当前界面的方向,而不是旧的接口方位上是removeFromSuperview显示?

回答

0

我认为这里的问题是,你最初添加一个viewController.view ontop的另一个然后删除旧的。

窗口的问题只需要一个rootViewController。所以窗口只会将旋转事件传递到第一个控制器上。意思是你的第二个viewController不会获得旋转事件,直到CompletionsBlock被调用。

我想要解决这个问题的方法是将此切换代码放在窗口中的rootViewController中。然后,无论何时进行切换,您都可以传入rootviewController的当前循环,并使您的authenticationViewController根据您传递的方向进行设置

相关问题