【问题标题】:How to determine the coordinates of iPad's bottom right corner in landscape mode?横屏模式下如何确定iPad右下角的坐标?
【发布时间】:2013-04-22 19:03:46
【问题描述】:

我正在尝试在主视图的右下角放置一个子视图 (buttView)(来自代码,而不是来自 IB)。

以下代码有效

const float bottom = self.frame.size.height;
const float left   = self.frame.size.width;
NSLog(@"bottom=%.1f left=%.1f", bottom, left);
CGSize bz = buttView.frame.size;
CGRect rc = CGRectMake(left-bz.width, bottom-bz.height, bz.width,bz.height);
buttView.frame = rc;
[self addSubview:buttView];

但我很困惑,因为根据日志消息,bottom=1004.0 和 left=768.0,而 iPad横向模式!(宽度要大于高度!??)

此外,如果我 在 IB 中关闭“autoresize subviews”,那么代码只有在我交换 bottomleft 时才能工作(但它不能完美工作,因为真正的宽度是1024 而不是 1004)。

我的问题是:当视图处于横向模式时,是否有一种优雅的方法来确定视图右下角的位置?

【问题讨论】:

  • +1 表示格式良好的帖子,其中包括代码、您尝试过的内容以及具体的、可回答的问题。

标签: ios ipad landscape


【解决方案1】:

如果您在 viewWillLayoutSubviews 中查看这些值,并且使用边界而不是框架,您将获得正确的值,并且如果您旋转设备,它们将被更新。

【讨论】:

    猜你喜欢
    • 2013-10-13
    • 1970-01-01
    • 2018-12-29
    • 1970-01-01
    • 1970-01-01
    • 2021-10-30
    • 2012-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多