Is there something I'm missing here? i want the imageview to slide in then slide out from the bottom of the screen.

also, this seems to put the UIImageView behind the navigation bar how can I make a CGRect to fit the screen under the navbar?

_finga = [[UIImageView alloc] initWithFrame:CGRectMake(0, 88, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-88)];
hiddenFrame = CGRectOffset(_finga.frame, 0, _finga.frame.size.height);
_finga.frame = hiddenFrame;
[self.view addSubview:_finga];
_finga.image = [UIImage imageNamed:@"Finga"];
[UIView animateWithDuration:2.0 animations:^{
    _finga.frame = self.view.bounds;
}completion:^(BOOL done) {
    if (done) {
        NSLog(@"Complete!");
        [UIView animateWithDuration:2.0 animations:^{
            _finga.frame = hiddenFrame;
        }];
    }
}];
有帮助吗?

解决方案

The CGRect you initialize _finga with would put it under the nav bar. In the animation, you are setting the frame to the bounds of the view, which would put it behind the bar, since the y value would be 0.

You could write less code by initializing _finga with this frame from the start:

CGRectMake(0,
           self.view.bounds.size.height,
           self.view.bounds.size.width,
           self.view.bounds.size.height-88);

That will put the view off the screen. Then after you add it as a subview and set its image, animate the view back up to this frame:

CGRectMake(0,
           88,
           self.view.bounds.size.width,
           self.view.bounds.size.height-88);

Which will put the view just below the nav bar. Consider also replacing all the hard coded 88s with a variable or #define so that you can play around with it more easily and in case the nav bar height ever changes.

As for the completion block, try logging that @"Complete!" string before you check if done is YES, or put a breakpoint there and see what the value of done is. Your animation may not be completing for some reason, which would explain why the code in the completion block is not being run.

Generally, though, if you are just using the completion block to run another animation after the first one, you don't need to check the done BOOL at all. It's only crucial when something else in your program depends on the state of the animation. For example, the user may click a button which animates something and then takes the user to a different section of the app. But if the user cancels the animation, you may not want to go to the other section after all, so you can check done.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top