首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UIImage/UIView不能正确调整为UIInterfaceLandscape视图

UIImage/UIView不能正确调整为UIInterfaceLandscape视图
EN

Stack Overflow用户
提问于 2011-10-07 08:00:36
回答 1查看 157关注 0票数 1

我正在写一个应用程序,我想只在横向模式下查看。我已经对它进行了设置,如果iPhone处于纵向模式,则不会发生任何事情,并且当前图像仍处于横向模式。iPhone模拟器在横向模式下启动,主页按钮在右侧。如果将iPhone从一种横向模式旋转到另一种横向模式,则会发生动画并调整视图。但是,只要设备处于横向模式,并且主页按钮位于左侧,图像就会比所需的高出20像素,从而在屏幕底部显示一条白线。

尽管对此进行了逻辑调整的所有尝试,例如

代码语言:javascript
运行
复制
self.view.frame = CGRectMake (0,20, self.view.frame.size.width, self.view.frame.size.height)

这并不能解决问题。我在我的计算中考虑了状态栏。

.xib文件在UIImageView的顶部包含一个UIView。这是我第一次实现这些方法,所以如果解决方案相对简单,我深表歉意。下面是用于实现横向模式视图的两个方法的代码。

代码语言:javascript
运行
复制
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    //set up interface to only be viewed in Landscape

    if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        return interfaceOrientation;
    else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
        return interfaceOrientation;
    else
        return NO;
}

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)tointerfaceOrientation duration:(NSTimeInterval)duration {

    if(UIInterfaceOrientationLandscapeRight){ 
        self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); 
    }
    else if (UIInterfaceOrientationLandscapeLeft) { 

         //shouldn't adjustment to 20 fix the view?
        self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    }
    else return;
}
EN

回答 1

Stack Overflow用户

发布于 2011-10-07 08:04:27

为了让UIViews正确地调整子视图,您必须查看UIView属性:autoresizingMask,并将掩码设置为自动调整所需内容的大小,如果这不起作用,您将不得不重写:

代码语言:javascript
运行
复制
- (void)layoutSubviews

参考资料:UIView reference

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7681823

复制
相关文章

相似问题

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