15
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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) {
                         
                     }];
}
15
16
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
15
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?