0

I know there are some questions about UIImageView full-size have been asked but I'm still stuck with my problems.

I have a navigation bar, a scrollview, a UIImageView (named avatarTest) and a button. When I press the image, the UIImageView expand to full-size (320*480) and set the avatarTest.contentMode is ModeCenter.

My problems are:

  • UIImageView expanded to 320*480 but it didn't replace the navigation bar and status bar (like picture 1 and 2)

  • When I scroll down (now my button appear) and I press image, the UIImageView still expand according the old view. I want it expand to the full size, fill my current view (window) (like picture 3 and 4)

  • I want to know how to determine the origin frame (CGRectMake) of UIImageView by code so I can code for the 2nd press action (resize the image to origin)

enter image description here

enter image description here

enter image description here

enter image description here

Here are some my viewController.m codes:

- (IBAction) expand {

    [UIView animateWithDuration:0.5f animations:^{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
        CGFloat screenWidth = screenRect.size.width;
        CGFloat screenHeight = screenRect.size.height;            
        avatarTest.frame=CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, screenWidth, screenHeight);
        avatarTest.contentMode=UIViewContentModeCenter;
        avatarTest.backgroundColor = [UIColor blackColor];


    }]; 
} 
4

2 回答 2

3

首先,你必须确保你的框架是正确的。我注意到您保留了原点的 x 和 y,也许每次都必须重置它们。一些实验很快就会产生预期的结果。

其次,通过设置contentModeUIViewContentModeCenter防止图像被缩放。您需要启用一种内容模式来缩放图像,如下所示:

UIViewContentModeScaleToFill
UIViewContentModeScaleAspectFit
UIViewContentModeScaleAspectFill

最后,要覆盖导航栏,您必须从主视图中删除视图并将其添加到窗口中。

[avatarTest removeFromSuperview]; 
[self.view.window addSubview:avatarTest]; 

当然,要重置,您将不得不做相反的事情。
另外,我建议在viewDidDisappear.

于 2013-03-05T17:21:16.113 回答
2

要摆脱状态栏和导航栏,您必须隐藏它们。在没有动画的情况下隐藏它们......

[self.navigationController setNavigationBarHidden:YES animated:NO];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];

当然,当您想要它们回来时,您必须将隐藏设置为 NO。

于 2013-03-05T17:25:23.490 回答