ios - 在 ios 中更改方向时设置框架大小

标签 ios xcode

我想在 ios 6 中更改 View 的方向。当方向更改时,我想设置 View 的框架大小。

我的方向更改示例代码:

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSInteger)supportedInterfaceOrientations
{
    NSInteger mask = 0;

    intOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    if(intOrientation == UIInterfaceOrientationPortrait || intOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        mask |= UIInterfaceOrientationMaskPortrait;
    } else 
        if(intOrientation == UIInterfaceOrientationLandscapeLeft)
        {
            mask |= UIInterfaceOrientationMaskLandscapeLeft;
        }
    }
    NSLog (@"mask %d",mask);
    return mask;
}

// Here now mask value is 2 because my default mode is portrait. 

现在,当我将方向更改为横向时,我想设置框架大小。请指导我如何做到这一点。

好的..我可以通过获取版本并在 viewdidLoad 中比较它来像 dis 一样设置 View 的帧大小吗:

orientation = [[UIDevice currentDevice] orientation];

NSString *reqSysVer = @"6.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
NSLog (@"ios version %@",currSysVer);
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
{
    if (orientation == UIInterfaceOrientationMaskPortrait) {
        self.view.frame = CGRectMake(0, 0, 1000, 800);


        self.tableView1.frame = CGRectMake(1, 0, 764,510);

    }
    else if (orientation == UIInterfaceOrientationMaskLandscapeLeft)
    {
        self.view.frame = CGRectMake(0, 0, 1300, 370);
        self.tableView1.frame = CGRectMake(0, 0, 1300, 370);
        self.view.backgroundColor = [UIColor blackColor];

    }

}

最佳答案

您可以在界面方向发生变化时收到通知:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];

并添加如下函数:

- (void)didRotate:(NSNotification *)notification {   
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    if (orientation == UIDeviceOrientation...)
    {
        // add some code
    }
}

关于ios - 在 ios 中更改方向时设置框架大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14702949/

相关文章:

iphone - 从 UITextView 获取文本的来源

JavaScript doOnOrientationChange :can't fix a bug loading the page

c# - Xamarin 表格 : Resource strings

ios - 在内存结构中捕获 NSLog 输出

ios - Xcode - 无法在脚本中使用 PlistBuddy 修改 plist

iphone: 在 UIWebView 中弹出按钮

ios - 无法添加托管在 OS X Server 上的 Git 存储库

ios - 如何在 Swift3 中使用可选动画实现功能

ios - 我的应用程序二进制文件在 Xcode 中的哪里提交?

ios - 我的油漆泄漏内存?