iphone - iOS UIImageView 位置

标签 iphone ios uiimageview

我需要将图像放在屏幕底部,因此我使用 UIImageView 并尝试了两种方法来指定其位置:

someImageView.frame=CGRectMake(x, y, a, b);
[someImageView initWithFrame:CGRectMake(x, y, a, b)];

但它显示在顶部,覆盖导航栏。我做错了什么?您建议做什么?

提前谢谢您。

最佳答案

您确定假设的屏幕坐标正确吗?屏幕的原点位于左上角,而不是左下角。尝试在 Interface Builder 中添加一个对象并在其中检查其框架。

我对上面代码片段中的第二行有点困惑。您是否在已初始化的对象上调用 initWithFrame: ?如果是这样,您可能会看到一些意想不到的行为。应声明对象:

UIImageView *someImageView = [[UIImageView alloc] initWithFrame:frame];

而不是:

UIImageView *someImageView = [UIImageView alloc];
[someImageView initWithFrame:frame];

始终将 allocinit 保持在同一行代码中。

关于iphone - iOS UIImageView 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7392511/

相关文章:

iphone - UITableView 是 "loaded"委托(delegate)吗?

iphone - 如何获得模式为 AspectFit 的 UIImageView 的比例因子?

ios - 如何使用for循环创建UIImageView动态网格?

swift - 键盘上方的 View 不显示

iphone - 如何编辑plist文件中特定的NSDictionary?

iphone - 多个 UIButtons 1 函数

iphone - 本地化日期不翻译日期

ios - CFRelease 与 CGPathRelease

ios - Xcode 6 中与 iPhone 5/6/6+ 屏幕分辨率相关的相同按钮位置

ios - UITableViewCell 的 UIImage 的内存在 segue 后退按钮后未释放