定位在ios6中不起作用?

时间:2012-12-07 07:00:01

标签: iphone objective-c ios orientation

我在ios6的Orientation中遇到问题。相同的代码适用于ios5或5.1。     我根据ios6标准使用了- (BOOL) shouldAutorotate and -(NSInteger)supportedInterfaceOrientations。但仍然没有调用“willRotateToInterfaceOrientation”和“didRotateToInterfaceOrientation”。

这是我的代码: -

- (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.

请帮我解决这个问题。我无法找到解决方案。谢谢你提前!!。

1 个答案:

答案 0 :(得分:0)

ios6中,您必须将此方法用于 vieworientation

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskAll;
}

并查看我的回答Link