HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iOS 4.3用户界面方向问题,带有20个状态栏大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个视图控制器:

> FirstViewController
> SecondViewController
> ThirdViewController

目标是:通过SecondViewController呈现ThirdViewController.

在FirstViewController中,我使用下面的方法呈现SecondViewController:

[self presentModalViewController:secondViewController animated:NO];

当加载SecondViewController时,我在-viewDidAppear中呈现ThirdViewController:委托回调方法

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self presentModalViewController:thirdViewController animated:NO];
}

因此,我认为现有视图控制器的方案已为我们所有人所知.也许代码的设计不好,但我已经制定了这个解决方案并且有下面描述的问题.

当加载ThirdViewController时,我遇到了20分的问题(但仅适用于iOS 4.3,其他版本运行良好).

我有附件显示我的问题.

正如你在左侧看到的那样,我有不必要的偏移量.旋转屏幕后,此问题消失.

当我打印ThirdViewController视图框架时,它显示frame =(0 0; 480 300).也许是SecondViewControllers视图中的问题.

关于轮换.我已经在每个控制器中实现了以下这些方法

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight)
        return YES;

    return NO;
}

(更新:)是的我现在发现了问题,SecondViewController帧=(0 20; 300 480);但我不明白为什么.

添加方法以检查当前方向:

-(void) getCurrentOrientation{

    UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

    if(orientation == UIInterfaceOrientationPorTrait){
        NSLog(@"porTrait");
    } else if(orientation == UIInterfaceOrientationLandscapeRight) {
        NSLog(@"LandscapeRight");
    } else if(orientation == UIInterfaceOrientationLandscapeLeft) {
        NSLog(@"LandscapeLeft");
    }
}

并在-viewDidAppear:方法检查它,它显示当前方向是纵向而不是我在shouldAutorotateToInterfaceOrientation回调中设置的横向模式.

此外,我发现对于iOS iOS 4.3,它的效果很好.

我在iPhone模拟器上做了所有测试.

我已将此代码添加到我的基本视图控制器,但它仍然不适合我.

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
        //Landscape orientation code

        if (IS_IPAD) {
            [self.view setFrame:CGRectMake(0,1024,748)];
        }
        else if (IS_IPHONE) {
            [self.view setFrame:CGRectMake(0,480,300)];
        }
        else if (IS_IPHONE_5) {
            [self.view setFrame:CGRectMake(0,568,300)];
        }

        NSLog(@"landscape");
        NSLog(@"%@",[NSValue valueWithCGRect:self.view.frame]);

    }else {
        //porTrait orientation code
        NSLog(@"porTrait");
    }
}

(工作更新:)

我使用下面的代码解决了这个问题:

[UIApplication sharedApplication].statusBarHidden = YES;
if (self.thirdViewController) self.thirdViewController = nil;
self.thirdViewController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController"] bundle:nil];
[self presentModalViewController:self.self.thirdViewController animated:NO];
[UIApplication sharedApplication].statusBarHidden = NO;

解决方法

亚历山大,请你试试下面的代码.它工作在4.3(添加到SecondViewController):

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    [UIApplication sharedApplication].statusBarHidden = YES;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    AMThirdViewController* th = [[AMThirdViewController alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:th animated:NO];
    [UIApplication sharedApplication].statusBarHidden = NO;
}

大佬总结

以上是大佬教程为你收集整理的iOS 4.3用户界面方向问题,带有20个状态栏全部内容,希望文章能够帮你解决iOS 4.3用户界面方向问题,带有20个状态栏所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。