0

I have got my view designed like that: under the bottom edge of the screen a subview is located. Once the app launched and viewDidLayoutSubviews called i animate the view sliding out from the bottom. My problem is - each time the status bar changes (receiving the call for example) the bottom view is been slide-out again. Here is my code:

        [UIView animateWithDuration:0.7 animations:^ {
            self.bottomView.frame = CGRectMake(0.0,
                                               self.view.frame.size.height - heightOfBot,
                                               self.bottomView.frame.size.width,
                                               self.bottomView.frame.size.height);

        }];
Zev Eisenberg
  • 8,080
  • 5
  • 38
  • 82
serg_ov
  • 563
  • 7
  • 18
  • I edited your tags. You’re not using `NSLayoutConstraint`, so you’re not using [Auto Layout](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html). – Zev Eisenberg Aug 07 '14 at 21:04
  • Oops, I take it back. – Zev Eisenberg Aug 08 '14 at 12:05

1 Answers1

0

Use a property:

@property (nonatomic) BOOL bottomViewVisible;

And a method:

- (void)showBottomView {
    if ( !self.bottomViewVisible ) {
        self.bottomViewVisible = YES;
        [UIView animateWithDuration:0.7 animations:^{
            self.bottomView.frame = CGRectMake(0.0,
                                               CGRectGetHeight(self.view.bounds) - heightOfBot,
                                               CGRectGetWidth(self.bottomView.frame),
                                               CGRectGetHeight(self.bottomView.frame));

        }];
    }
}

(I changed your CGRect direct member access to use the functions from CGGeometry.h as per the docs.)

Zev Eisenberg
  • 8,080
  • 5
  • 38
  • 82
  • You didn't understand me. I use autolayout. If i don't call above code in viewDidLayoutSubviews - view just disappears (hides to bottom). So i call the above code at least to have my view shown. Now i ask about if it's possible to make my view not hidden to bottom. – serg_ov Aug 08 '14 at 09:47
  • Ah, sorry. Didn't understand. When you're using auto layout, you shouldn't set the frame of a view yourself. I'll try to post another code sample later, but the gist is that you adjust your constraints and then, inside an animation block, call `[self.view layoutIfNeeded];`. – Zev Eisenberg Aug 08 '14 at 11:49
  • Should i still call the above code in viewDidLayoutSubviews or not? I suppose each time before viewDidLayoutSubviews called AutoLayout hides my view to bottom, as it was in the start. – serg_ov Aug 08 '14 at 12:02
  • No, you should replace it with code that modifies auto layout constraints. For example: http://stackoverflow.com/questions/12926566/are-nslayoutconstraints-animatable – Zev Eisenberg Aug 08 '14 at 12:03