UIView::addSubView 遮挡了原本位于顶部的导航栏
我为 ipad 设备设计了一个非常简单的界面:UIView + 导航栏。
然后,在视图加载后,它将从某个位置下载图像并使用以下方法来显示它:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
UIImage* testImg = [UIImage imageWithData:_networkData];
UIImageView* testView = [[UIImageView alloc] initWithImage:testImg];
[_view addSubview:testView];
[testView release];
}
现在的问题是新的 UIImage 占据了 Ipad 的整个可见区域。
我想知道如何解决这个问题?我想我必须找出原始视图中显示区域的框架,然后将其分配给 UIImageView 实例?
I designed a very simple interface for an ipad device: UIView + a navigation bar.
Then after the view is load, it will download an image from a location and use the following method to display it:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
UIImage* testImg = [UIImage imageWithData:_networkData];
UIImageView* testView = [[UIImageView alloc] initWithImage:testImg];
[_view addSubview:testView];
[testView release];
}
The problem is now the new UIImage occupies the whole visible area of the Ipad.
I wonder how can I fix this issue? I suppose I have to find out the frame of the display area in the original view, and then assign it to the UIImageView instance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
initWithImage
将自动调整框架以匹配您传入的图像的大小。要告诉UIImageView
采用与其父视图相同的大小,您只需添加在添加子视图之前添加以下行:...我们使用
bounds
而不是frame
因为超级视图可能具有我们不希望图像视图具有的偏移量。initWithImage
will automatically adjust the frame to match the size of the image you're passing in. To tell theUIImageView
to take the same size as its parent view you could just add the following line before you add the subview:...we use
bounds
rather thanframe
because the superview may have an offset that we don't want the image view to have.