在我的iOS应用程序中,界面是通过编程方式将多个UIViews添加到当前屏幕上的UIViewController中创建的。目前,应用程序工作在肖像方向,但我想增加工作能力,在景观。我想改变界面时,应用程序被放置在景观方向。锄头我能做这个吗?
我不能用界面生成器
发布于 2014-03-09 20:01:17
您需要通过NSNotificationCenter观察方向的变化,然后处理它。
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];然后创建处理旋转的方法。
- (void)orientationChanged:(NSNotification *)notification
{
// Get device orientation
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsPortrait(deviceOrientation))
{
// Portrait
}
else if(UIDeviceOrientationIsLandscape(deviceOrientation))
{
// Landscape
}
}https://stackoverflow.com/questions/22285516
复制相似问题