0
votes

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


    }]; 
} 
2
Your question does not make sense. How is picture 3 or 4 full size? What is the "old view"?Mundi

2 Answers

3
votes

First, you have to make sure your frames are correct. I notice that you are keeping the x and y of the origin, maybe these have to be reset each time. Some experimentation will soon lead to the desired result.

Second, by setting the contentMode to UIViewContentModeCenter you are preventing the image from being scaled. You need to enable a content mode that scales the image like one of these:

UIViewContentModeScaleToFill
UIViewContentModeScaleAspectFit
UIViewContentModeScaleAspectFill

Finally, to cover the navigation bar, you will have to remove the view from the main view and add it to the window instead.

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

Of course to reset you will have to do the opposite.
Also, I recommend to clean this up in viewDidDisappear.

2
votes

To get rid of the status bar and the navigation bar you have to hide them. To hide them without animation...

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

And of course when you want them back you'll have to set hidden to NO.