开发者

UIView::addSubView obstructs the navigation bar originally at the top

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];
}

T开发者_Python百科he 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?


initWithImage will automatically adjust the frame to match the size of the image you're passing in. To tell the UIImageView to take the same size as its parent view you could just add the following line before you add the subview:

testView.frame = _view.bounds

...we use bounds rather than frame because the superview may have an offset that we don't want the image view to have.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜