需要帮助检查 iPad 的方向

发布于 2024-11-30 20:39:00 字数 597 浏览 2 评论 0原文

可能的重复:
iPhone 方向

根据 iPad 的方向,我需要设置表格视图的背景或将其删除,因为它不适用于弹出窗口。

我尝试过,但没有运气:

if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft ){
    self.navigationController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]; 
    self.tableView.backgroundColor = [UIColor clearColor];
    NSLog(@"test");

也许有更好的方法?查看表格是主表格还是弹出窗口,然后设置背景?

Possible Duplicate:
iPhone orientation

Depending on what orientation the iPad is in, I need to either set the table view's background or remove it because it doesn't work with the popover.

I tried this but no luck:

if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft ){
    self.navigationController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]; 
    self.tableView.backgroundColor = [UIColor clearColor];
    NSLog(@"test");

Maybe there is a better way? To see if table is master or popover, then set background?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

动次打次papapa 2024-12-07 20:39:00

有几种方法可以或多或少地实现您想要的效果:

  1. UIInterfaceOrientationorientation = [[UIDevice currentDevice]orientation];
  2. 一种更黑客的方法是检查状态栏的宽度。

如果您选择选项 1,那么您可以像这样检查方向:

switch (orientation) {
    case UIInterfaceOrientationPortrait:
        // Do something.
        break;
    case UIInterfaceOrientationPortraitUpsideDown:
        // Do something.
        break;
    case UIInterfaceOrientationLandscapeLeft:
        // Do something.
        break;
    case UIInterfaceOrientationLandscapeRight:
        // Do something.
        break;
}

编辑:要让您的应用程序自动旋转,您可以执行以下操作:

- (BOOL)willAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if ((interfaceOrientation == UIDeviceOrientationLandscapeRight)) NSLog(@"Right");
    if ((interfaceOrientation == UIDeviceOrientationLandscapeLeft)) NSLog(@"Left");
    if ((interfaceOrientation == UIDeviceOrientationPortrait)) NSLog(@"Up");
    if ((interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)) NSLog(@"Down");
    return YES;
}

There are several ways to achieve what you want, more or less:

  1. UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
  2. A more hack-ish method would be to check the width of the status bar.

If you go with option 1, then you can check the orientation like so:

switch (orientation) {
    case UIInterfaceOrientationPortrait:
        // Do something.
        break;
    case UIInterfaceOrientationPortraitUpsideDown:
        // Do something.
        break;
    case UIInterfaceOrientationLandscapeLeft:
        // Do something.
        break;
    case UIInterfaceOrientationLandscapeRight:
        // Do something.
        break;
}

EDIT: To get your application to automatically rotate, you can do this:

- (BOOL)willAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if ((interfaceOrientation == UIDeviceOrientationLandscapeRight)) NSLog(@"Right");
    if ((interfaceOrientation == UIDeviceOrientationLandscapeLeft)) NSLog(@"Left");
    if ((interfaceOrientation == UIDeviceOrientationPortrait)) NSLog(@"Up");
    if ((interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)) NSLog(@"Down");
    return YES;
}
剩余の解释 2024-12-07 20:39:00
UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation;
UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文