当iphone发生横向定位时出现问题

时间:2010-07-02 06:15:30

标签: iphone objective-c cocoa-touch

我在iphone应用程序中使用委托方法进行自动旋转。

    -(BOOL)shouldAutorotateToInterfaceOrientation:UIInterfaceOrientation)interfaceOrientation{

    if(interfaceOrientation  == UIInterfaceOrientationPortrait ){
            [UIView beginAnimations:@"View Flip" context:nil];
            [UIView setAnimationDuration:0.2f];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            self..view.transform = CGAffineTransformMakeRotation(0);
            self.view.bounds = CGRectMake(0,0,320,460);
            [UIView commitAnimations];
            self.navigationBar.frame=CGRectMake(0, 0, 320, 44);


        }else if(interfaceOrientation  == UIInterfaceOrientationLandscapeRight){

            [UIView beginAnimations:@"View Flip" context:nil];
            [UIView setAnimationDuration:0.2f];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2);
            self.view.transform = transform;
            CGRect contentRect = CGRectMake(10, -10, 480, 300);
            self.view.bounds = contentRect;
            [UIView commitAnimations];

            self.navigationBar.frame=CGRectMake(0, 0, 480, 32);

        }else if(interfaceOrientation  == UIInterfaceOrientationLandscapeLeft){
            //navigationController.navigationBar.frame=CGRectMake(0, 0, 480, 34);
            [UIView beginAnimations:@"View Flip" context:nil];
            [UIView setAnimationDuration:0.2f];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            CGAffineTransform transform = CGAffineTransformMakeRotation(-3.14159/2);
            self.view.transform = transform;
            CGRect contentRect = CGRectMake(-10, -10, 480, 300);
            self.view.bounds = contentRect;
            [UIView commitAnimations];

            self.navigationBar.frame=CGRectMake(0, 0, 480, 32);
        }else if(interfaceOrientation  == UIInterfaceOrientationPortraitUpsideDown ){
               return NO;
        }
        return YES;
    }

在iphone OS3上工作正常,但在iphone OS4上,当转为横向模式时,界面显示不正确

Landscape

当旋转回纵向模式时,接口压缩.... Portrait

请建议我如何解决它?

感谢
迪皮卡乌达

1 个答案:

答案 0 :(得分:0)

CGRect contentRect = CGRectMake(-10,-10,480,300);             self.view.bounds = contentRect;

为什么你给-10,-10?任何具体原因。这完全是由于帧不匹配造成的。只需更改该帧并进行检查即可。