简体   繁体   中英

iOS Bring Subview To Front not working on UIImageView

I know that I should be able to do this:

[self.view bringSubviewToFront:myImageView];

And that it should bring the image view to the front. myImageView has been set in a storyboard, and linked in to the code using @property and @synthesize. I'm able to do other manipulations (loading images and scaling up via animation) but can't seem to get the view to take up the uppermost view. So when the animation is finished there is an overlap to another image view.

The view it's part of is a modally presented view controller. Either on iPhone or iPad form sheet. Not working on both. Also running iAd.

What I find strange too is when I do:

NSLog(@"number of subviews %d", self.view.subviews.count);

I get a result of 1.

Any suggestions? I've used this method before with other apps and it worked, but my searches suggest that I'm doing it right. So where else have I gone wrong? I'm thinking it must be to do with not being in the right self.view but can't understand why that would be.

Further code as requested:

[self.view bringSubviewToFront:myImageView];
        [UIView animateWithDuration:0.35 delay:0 options:0 animations:^{
            //save previous frame
            prevFrame = myImageView.frame;
            float width = [[UIScreen mainScreen] bounds].size.width;
            float height = [[UIScreen mainScreen] bounds].size.height;
            // Need to create a 320x320 centred square
            float originX = (width - 320)/2;
            float originY = (height -320)/2;
            CGRect newFrame = CGRectMake( originX, originY, 320, 320);
            [myImageView setFrame:newFrame];
        }completion:^(BOOL finished){
        }];

So you see most of the code is just about the animation of the image to expand it to the centre of the display. But I am able to manipulate the image as you would expect, but it's not responding to the message to take it to the front of the view. Normally that's self.view bringSubviewToFront and that would work, but I think the message is going to the wrong view and I can't think why?

if you have 2 images on each other just use

 [imageView setHidden:YES];

to Hide it and

[imageView setHidden:No];

to show it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM