简体   繁体   English

方向不适用于ios6?

[英]Orientation is not working in ios6?

I am having problem in Orientation for ios6. 我在ios6的定向中遇到问题。 same code is working fine for ios5 or 5.1. 相同的代码适用于ios5或5.1。 I have used - (BOOL) shouldAutorotate and -(NSInteger)supportedInterfaceOrientations as per the ios6 standard. 我已经按照ios6标准使用了- (BOOL) shouldAutorotate and -(NSInteger)supportedInterfaceOrientations But still " willRotateToInterfaceOrientation " and " didRotateToInterfaceOrientation " is not getting called. 但是仍然没有调用“ willRotateToInterfaceOrientation ”和“ didRotateToInterfaceOrientation ”。

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 !!. 我无法为此找到解决方案。谢谢!!

In ios6 you have to use this method for vieworientation ios6您必须使用此方法进行vieworientation

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskAll;
}

And check my answer Link 并检查我的答案链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM