【发布时间】:2015-04-24 08:29:55
【问题描述】:
我将图像视图传递给需要图像视图大小的 init 方法。然后调用convertRect:toView:
- (id) initWithImageView:(UIImageView*) imageView {
self = [super init];
if (self) {
CGRect imageViewFrame = [[imageView superview] convertRect: imageView.frame toView: self.view];
}
}
调用方式:
MyViewController *viewController = [[MyViewController alloc] initWithImageView:imageView];
viewController.delegate = self;
[self.tabBarController presentViewController:viewController animated:NO completion:nil];
imageViewFrame 然后是
(origin = (x = 0, y = -120.22867049625003), size = (width = 750, height = 750))
imageView 有一帧
frame = (0 -60.1143; 375 375);
它的超级视图是有一个框架
frame = (0 0; 375 254.5);
为什么要放大 2 倍?
在 iPhone 6 plus (3x) 模拟器上进一步测试生成 imageViewFrame
(origin = (x = 0, y = -199.30952358000002), size = (width = 1242, height = 1242))
第一次测试是在 iPhone 6 模拟器 (2x) 上完成的。 为什么 convertRect:toView: 以像素而不是点工作?
【问题讨论】:
-
你将 ImageView 传递给什么类?是 UIScrollView 还是类似的东西?
-
你为什么不直接使用imageview的框架比如:
CGRect imageViewFrame = imageView.frame; -
ps4 - 它只是一个 UIViewController 子类
-
Mrunal - 因为我不知道 [imageView superview] 会一直处于 0,0。
-
你应该提供更多的代码,现在很难说是什么问题。你在哪里调用这个初始化函数?可以展示一下吗?
标签: ios cocoa-touch uiview uikit retina-display