以横向模式捕捉视图

时间:2013-12-27 13:45:54

标签: ios iphone objective-c

在我的视图中,视图底部有按钮,我将按钮位置更改为4英寸和3.5英寸但是横向模式按钮保持在视图下方,我想在横向模式下捕捉视图,这样我就可以编写新的代码了按钮位置,

如何在横向模式下捕捉视图。我尝试了很多代码,没有一个没用。

我的初步观点是UINavigationView, 这是我的代码;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    if (screenBounds.size.height == 568)
    {


    //do below if it is portrait
        buttonnewreg.frame = CGRectMake(0.0, self.view.frame.size.height - 2, 320.0, 46.0);
        buttonadminreq.frame = CGRectMake(0.0, self.view.frame.size.height  + 42, 320.0, 46.0);

    //do something if it is landscape 
           ???

    }

}

我需要if语句

感谢名单

2 个答案:

答案 0 :(得分:0)

注册方向更改通知和/或实施方向处理方法并在那里重新定位按钮。

在功能 UIDeviceOrientationIsLandscape

中查看UIKit功能参考

假设实现两个方法 doLandscapeStuff doPortraitStuff ,可以使用它的示例。

// get the device orientation
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
// conditional for device orientation
(UIDeviceOrientationIsLandscape(orientation)) ? [self doLandscapeStuff] :
                                                [self doPortraitStuff];

因为你说“我需要if语句”改为

// get the device orientation
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;

// conditional for device orientation
if (UIDeviceOrientationIsLandscape(orientation)) {

     // do landscape stuff here...

}

答案 1 :(得分:0)

这样做:

 -(void)viewDidLoad
{

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

}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];

}

-(void)orientationChanged
{
   //Handle OrientationChange
}