我希望视图保持静态,但内容在视图内重新定向

发布于 2024-11-07 19:10:54 字数 82 浏览 4 评论 0原文

我正在为 iPad 创建一个包含多个子视图的视图。我希望旋转 iPad 时子视图的所有位置和大小保持不变,但子视图内的内容重新定向。有谁知道该怎么做?

I am making a view with several subviews for iPad. I want all the positioning and sizing of the subviews to stay the same when rotating the iPad, but the content inside the subviews to re-orient. Does anyone know how to do this?

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

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

发布评论

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

评论(1

诺曦 2024-11-14 19:10:54

听起来您仍然需要根据方向来布局视图。但是,纵向和横向框架在屏幕上的比例会有所不同。

如何布局视图的示例:

int h = 300;
int w = 100;
int space = 50;

CGRect frame;
if( interfaceOrientation == UIInterfaceOrientationPortrait ) {

   frame = CGRectMake( space, space, w, h );
}
else if( interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ) {
    frame = CGRectMake( self.view.bounds.size.width - w - space, self.view.bounds.size.height- h - space, w, h );
}
else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight ) {
    frame = CGRectMake( space, self.view.bounds.size.height- w - space, h , w );
}
else if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) {
    frame = CGRectMake( self.view.bounds.size.width - h - space, space, h, w );
}

self.label.frame = frame;

It sounds like you still need to layout the views depending on the orientation. However, you're portrait and landscape frames would have different proportions on the screen.

An Example of how you might layout a view:

int h = 300;
int w = 100;
int space = 50;

CGRect frame;
if( interfaceOrientation == UIInterfaceOrientationPortrait ) {

   frame = CGRectMake( space, space, w, h );
}
else if( interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ) {
    frame = CGRectMake( self.view.bounds.size.width - w - space, self.view.bounds.size.height- h - space, w, h );
}
else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight ) {
    frame = CGRectMake( space, self.view.bounds.size.height- w - space, h , w );
}
else if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) {
    frame = CGRectMake( self.view.bounds.size.width - h - space, space, h, w );
}

self.label.frame = frame;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文