[英]change custom label and button to landscape in xcode 5
我分别在纵向和横向模式下创建了一个自定义按钮和标签,如下所示:
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait) {
[self addButton1];
[self addLabel1];
}
else if(orientation == UIInterfaceOrientationLandscapeRight)
{
[self addButton2];
[self addLabel2];
}
return YES;
}
如果我运行此代码,则在横向模式下会同时显示按钮和标签。 如果我尝试这样:
else if(orientation == UIInterfaceOrientationLandscapeRight)
{
[self addButton2];
[self addLabel2];
[custombtn1 setHidden:YES];
}
错误:使用未声明的标识符。 有人可以帮我吗?
您需要实现该方法:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
无论您的代码执行单步旋转还是两步旋转,都将调用此方法。
参数
fromInterfaceOrientation
用户界面的旧方向。 有关可能的值,请参见UIInterfaceOrientation。
此外,您可以隐藏不必要的按钮。
addButton2.hidden = YES;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.