首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何提供纵向和横向两种不同的视图?

问如何提供纵向和横向两种不同的视图?
EN

Stack Overflow用户
提问于 2013-01-14 16:58:30
回答 3查看 3.2K关注 0票数 1

我目前正在使用一个有“时间表”的IPhone应用程序。在肖像,我希望它有一个常规的表视图与一些自定义!当我有了横向的IPhone时,我想让它变成一个更“时间表”的-view,有表格和行。

有可能吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-01-14 17:06:47

请参阅苹果文档Creating an Alternate Landscape Interface

请务必阅读文档,但以下是示例实现的代码:

代码语言:javascript
复制
@implementation PortraitViewController
- (void)awakeFromNib
{
    isShowingLandscapeView = NO;
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                 selector:@selector(orientationChanged:)
                                 name:UIDeviceOrientationDidChangeNotification
                                 object:nil];
}

- (void)orientationChanged:(NSNotification *)notification
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
        !isShowingLandscapeView)
    {
        [self performSegueWithIdentifier:@"DisplayAlternateView" sender:self];
        isShowingLandscapeView = YES;
    }
    else if (UIDeviceOrientationIsPortrait(deviceOrientation) &&
             isShowingLandscapeView)
    {
        [self dismissViewControllerAnimated:YES completion:nil];
        isShowingLandscapeView = NO;
    }
}
票数 1
EN

Stack Overflow用户

发布于 2013-01-14 18:00:55

尝尝这个

代码语言:javascript
复制
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {


    [self adjustViewsForOrientation:toInterfaceOrientation];

}

-(void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation
{
    if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        //write code for portrait mode
    }
    else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
    {
       //write code for landscape mode


    }
}
票数 2
EN

Stack Overflow用户

发布于 2013-01-14 17:10:52

答案是肯定的,可以通过以下方法实现:

代码语言:javascript
复制
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation)){
\\ your timetable customisation goes here
     }
}

您还需要以下内容:

代码语言:javascript
复制
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
       return YES;
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14315456

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档