Orientation is not working in ios6?

雨燕双飞 提交于 2019-12-14 04:09:37

问题


I am having problem in Orientation for ios6. same code is working fine for ios5 or 5.1. I have used - (BOOL) shouldAutorotate and -(NSInteger)supportedInterfaceOrientations as per the ios6 standard. But still "willRotateToInterfaceOrientation" and "didRotateToInterfaceOrientation" is not getting called.

Here is my code:--

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{

    if (!UIInterfaceOrientationIsPortrait(lastOrientation) || !UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) 
    if (!UIInterfaceOrientationIsLandscape(lastOrientation) || !UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) 
    {

        CGRect frame;
        int viewAlpha;
        lastOrientation = toInterfaceOrientation;

        if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
        {

            [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

            viewAlpha = 1;
            [MovieControlContainerLandscape setHidden:YES];


            if (isDauntless) {
                [self.navigationController setNavigationBarHidden:NO animated:YES];
            } else {
                [self.navigationController setNavigationBarHidden:NO];
            }


            frame = iPad ? CGRectMake(0, 88, 768, 432) : CGRectMake(0, 88, 320, 180);
            [movieContainer removeGestureRecognizer:toggleMediaControl];


        }
        else
        {
            [PromptToBuy dismissWithClickedButtonIndex:0 animated:YES];

            [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];

            viewAlpha = 0;
            [MovieControlContainerLandscape.layer setCornerRadius:22];
            [MovieControlContainerLandscape.subviews.lastObject addSubview:[MediaControls use]];


            if (isDauntless) {
                [self.navigationController setNavigationBarHidden:YES animated:YES];
            } else {
                [self.navigationController setNavigationBarHidden:YES];
            }


            frame = iPad ? CGRectMake(0, 0, 1024, 768) : CGRectMake(0, 0, 480, 320);

            [movieContainer addGestureRecognizer:toggleMediaControl];

            if (isDauntless) {
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:0.6];
            }

            if(TSFullScreen)
            {
                [movieContainer setAlpha:1];
            }

            if (isDauntless) {
                [UIView commitAnimations];
            }

        }

        [viewContainer setAlpha:viewAlpha];

        // Size the overlay view for the current orientation.
        [movieContainer setFrame:frame];

    }

}


/* Sent to the view controller after the user interface rotates. */
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{

    if (!UIInterfaceOrientationIsPortrait(lastOrientation) || !UIInterfaceOrientationIsPortrait(fromInterfaceOrientation)) 
    if (!UIInterfaceOrientationIsLandscape(lastOrientation) || !UIInterfaceOrientationIsLandscape(fromInterfaceOrientation)) 
    {

        float duration = .5;

        if (fromInterfaceOrientation == UIInterfaceOrientationPortrait || fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
        {

            if (isDauntless) {
                [UIView transitionWithView:movieContainer duration:duration options:UIViewAnimationOptionTransitionNone animations:^{

                    /* Move movie view to parent center. */
                    [self.moviePlayerController.view setCenter:movieContainer.center];

                } completion:^(BOOL finished) {

                    [UIView beginAnimations:nil context:NULL];
                    [UIView setAnimationDuration:duration];
                    CGRect frame = movieContainer.frame;
                    /* Size movie view to fit parent view. */
                    frame.origin.y = 0;
                    [self.moviePlayerController.view setFrame:frame];
                    [UIView commitAnimations];

                    CGPoint center = CGPointMake(movieContainer.center.x, -50);
                    [MovieControlContainerLandscape setTag:0];
                    [MovieControlContainerLandscape setHidden:NO];
                    [MovieControlContainerLandscape setCenter:center];

                    [self toggleMovieController];

                }];

            } else {

                CGRect frame = movieContainer.frame;
                /* Size movie view to fit parent view. */
                frame.origin.y = 0;
                [self.moviePlayerController.view setFrame:frame];

                CGPoint center = CGPointMake(movieContainer.center.x, -50);
                [MovieControlContainerLandscape setTag:0];
                [MovieControlContainerLandscape setHidden:NO];
                [MovieControlContainerLandscape setCenter:center];

                [self toggleMovieController];

            }


        }
        else
        {

            if (!isDauntless) {
                [MovieControlContainer setFrame:CGRectMake(0, 44, 768, 68)];
            }

            [MovieControlContainer addSubview:[MediaControls use]];

            //NSLog(@"MovieControlContainer is %@, MovieControlContainer subviews: %@",MovieControlContainer,[MovieControlContainer subviews]);


            if (isDauntless) {
                [UIView beginAnimations:nil context:NULL];
                [UIView setAnimationDuration:duration];
            }

            if(TSFullScreen){
                [movieContainer setAlpha:0];
            }

            CGRect frame = movieContainer.frame;
            /* Size movie view to fit parent view. */
            frame.origin.y = 0;
            [self.moviePlayerController.view setFrame:frame];

            if (isDauntless) {
                [UIView commitAnimations];
            }

        }

    }

}



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

        return !mediaTypeIsAudio && isOrientationSupported;

}



//----supported method for ios6--------//


- (BOOL) shouldAutorotate
{
    return YES;
}




-(NSInteger)supportedInterfaceOrientations{

    NSInteger mask = 0;
    if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight])
        mask |= UIInterfaceOrientationMaskLandscapeRight;
    if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeLeft])
        mask |= UIInterfaceOrientationMaskLandscapeLeft;
    if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortrait])
        mask |= UIInterfaceOrientationMaskPortrait;
    if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortraitUpsideDown])
        mask |= UIInterfaceOrientationMaskPortraitUpsideDown;
    return mask;

}

//i have set the rootviewcontroller in appdelegate file
 self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
    self.window.rootViewController = self.navigationController.

Please help me to take out from this problem. I am not able to find the solution for this.Thanks in Advance !!.


回答1:


In ios6 you have to use this method for vieworientation

-(BOOL)shouldAutorotate
{
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskAll;
}

And check my answer Link



来源:https://stackoverflow.com/questions/13758398/orientation-is-not-working-in-ios6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!