Question

I'm trying to make an image go full screen on tap, which doesn't sound so complicated.

This it currently doing the work after the tap is detected:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.view];

if (self.contentView.frame.origin.y >= 0 && CGRectContainsPoint(self.bottleImageView.frame, touchLocation)) {
    [UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
        [bottleImageView setFrame:[[UIScreen mainScreen] bounds]];
        bottleImageView.backgroundColor = [UIColor blackColor];
    }completion:^(BOOL finished){}];
...
}

There's a problem though. I need to bring the UIImageView to the front, so that it draws the image in front of the other views. When I add in [self.view bringSubviewToFront:bottleImageView]; to the mix (either before the animation block, in the completion block, or after this code), things change. On the first tap, the UIImageView background changes to black, and on the second tap the view expands to full screen.

I'm sure it's just something small and dumb that I've overlooked.

EDIT: I've added the touch code

EDIT (2): I may have missed some vital information. I thought I'd try auto layout for this project. I'm guessing there's something there that's not letting everything work as intended?

Was it helpful?

Solution 3

OK. The code above is fine for expanding a view.

I found there was a problem with the Autolayout restraints. I couldn't tell you exactly what I changed that fixed the problem - but a few hours debugging restraints solved the issue.

I found a much better solution however - Facebook POP works much better, and looks a lot slicker.

OTHER TIPS

You can use MHFacebookImageViewer

for this purpose. It is very simple to use.

Perhaps you have the wrong view content mode, add this line to where after the image is being set:

bottleImageView.contentMode = UIViewContentModeScaleAspectFit;

Add

[self.view bringSubviewToFront:bottleImageView] 

immediately after you add

[self.view addSubview:bottleImageView]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top