旋转设备加载childViewController,app减慢速度

时间:2013-12-13 04:47:52

标签: performance ios7 storyboard uideviceorientation childviewcontroller

我有一个带有4个视图控制器的故事板。 1 - initialViewController 2 - PortraitViewController 3- LeftLandscapeViewController 4 - RightLandscapeViewController。

当设备旋转时,新的viewcontroller将作为childViewController加载,并删除最后一个childViewController(如果存在)。

- (void)switchViews:(NSString*)storyboardId

{     __block UIViewController * lastController = _childController;

_childController = (UIViewController*)[self.storyboard instantiateViewControllerWithIdentifier:storyboardId];

[self addChildViewController:_childController];
[_parentView addSubview:_childController.view];

CGRect parentRect = _parentView.bounds;
parentRect.origin.x += parentRect.size.width;
_childController.view.frame = parentRect;
_childController.view.alpha = 0;

[UIView animateWithDuration:0.3 animations:^{
    _childController.view.frame = _parentView.bounds;
    _childController.view.alpha = 1.0;
} completion:^(BOOL finished) {
    if (lastController) // removes previous viewController
    {
        [lastController.view removeFromSuperview];
        [lastController removeFromParentViewController];
    }
}];

}

-(void)updateOrientationView

{

UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;



// --->         LANDSCAPE ROTATION
if(UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeRightView)
{

    if (deviceOrientation == UIDeviceOrientationLandscapeRight)
    {
        if([lastOrientation isEqual:@"landscapeRight"])                 
        {
            //NSLog(@"ROTATE TO LANDSCAPE RIGHT VIEW");

        }else{
            [self switchViews:@"landscapeRight"]; 
            lastOrientation = @"landscapeRight";
            NSLog(@"ROTATE TO LANDSCAPE RIGHT VIEW");
        }
    }


    if (deviceOrientation == UIDeviceOrientationLandscapeLeft)
    {
        if([lastOrientation isEqual:@"landscapeLeft"])
        {
            //
        }else{
            [self switchViews:@"landscapeLeft"];
            lastOrientation = @"landscapeLeft";
            NSLog(@"ROTATE TO LANDSCAPE LEFT VIEW");
        }
    }
}


if(UIDeviceOrientationIsPortrait(deviceOrientation) && !isShowingPortraitView)
{
    // ---> PORTRAIT
    if (deviceOrientation == UIDeviceOrientationPortrait)
    {
        if([lastOrientation  isEqual: @"portrait"])
        {
            //
        }else{
            [self switchViews:@"portrait"];
            lastOrientation = @"portrait";
            NSLog(@"ROTATE TO PORTRAIT VIEW");

        }
    }

    // ---> PORTRAIT UPSIDE DOWN
    if (deviceOrientation == UIDeviceOrientationPortraitUpsideDown)
    {
        //lastOrientation = @"portraitUpsideDown";
        // do nothing
    }
}

}

当我在我的设备上运行我的应用程序时,将它旋转后风景,然后肖像大约8次,我的应用程序是非常,非常顽固。我认为这是不正确的,因为我删除了以前的子视图?我想知道我的视图控制器是否被解雇/删除,或者是否有其他事情发生在这里?

感谢您提供任何指导

0 个答案:

没有答案
相关问题