LoginSignup
16
17

More than 5 years have passed since last update.

AutoLayout制約付きのViewを簡単にアニメーションさせる

Posted at

Masonryを使うとコードでのAutoLayoutの記述が簡単に書けます。

スクリーンショット 2014-10-24 11.00.55.png

view1には、Storyboardでtop,left,width,heightの制約を設定しており
view2には、left->view1から8,top,width,heightはview1と同じになるように設定してあります。

view1に対して、アニメーション処理を実行することでview2も追従することになります。

MAsonryを使ったアニメーション
- (IBAction)actionAnimationButton:(id)sender {

    [UIView animateWithDuration:0.3f
                          delay:0
                        options:UIViewAnimationOptionCurveEaseIn
                     animations:^{
                         [self.view1 mas_updateConstraints:^(MASConstraintMaker *make) {
                             make.top.mas_equalTo(arc4random() % 200 + 100);
                             make.height.mas_equalTo(arc4random() % 200 + 10);
                         }];

                         [self.view layoutIfNeeded];
                     } completion:^(BOOL finished) {

                     }];
}
16
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
17