【问题标题】:In iOS, how to move UI elements when a device rotate?在 iOS 中,如何在设备旋转时移动 UI 元素?
【发布时间】:2013-02-25 06:52:17
【问题描述】:

在 iOS 中,当设备从纵向模式旋转到横向模式时,如何移动 UI 元素(按钮和标签)?

【问题讨论】:

标签: iphone ios objective-c


【解决方案1】:

有很多方法。

就我而言,我正在使用通知

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rotated:) name:UIDeviceOrientationDidChangeNotification object:nil];

旋转方式

-(void) rotated: (NSNotification*) notification
{
    orientation = [[UIDevice currentDevice] orientation];
        if(UIDeviceOrientationPortraitUpsideDown==orientation) 
// UI relocation
else if(UIDeviceOrientationPortrait==orientation)
// UI relocation
else if(UIDeviceOrientationLandscapeRight==orientation)
// UI relocation
else if(UIDeviceOrientationLandscapeLeft==orientation)
// UI relocation
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-27
    • 2013-02-20
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 2013-03-01
    相关资源
    最近更新 更多