objective-c - ios 使用约束布局后动画失败
为情所困
为情所困 2017-05-02 09:34:40
0
1
492

运行这段代码后,动画效果失败

#import "ViewController.h"
#import "Masonry.h"
@interface ViewController ()
@property (nonatomic,strong)UIView *a;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIView *a = [[UIView alloc] init];
    a.backgroundColor = [UIColor redColor];
    [self.view addSubview:a];
    self.a = a;
    
    [a mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.bottom.equalTo(self.view.mas_bottom);
        make.height.equalTo(@100);
    }];
    
    
    UIButton *b = [[UIButton alloc] initWithFrame:CGRectMake(20, 20, 200 , 200)];
    b.backgroundColor = [UIColor greenColor];
    [self.view addSubview:b];
    [b addTarget:self action:@selector(ad) forControlEvents:UIControlEventTouchUpInside];
}

-(void)ad{
    [UIView animateWithDuration:2 delay:1 options:UIViewAnimationOptionCurveEaseIn animations:^{
        self.a.center = CGPointMake(self.a.center.x, self.a.center.y - 200);
    } completion:^(BOOL finished) {
        NSLog(@"11111 %@",self.a);

        [self.view addSubview:[[UIView alloc] init]];
          NSLog(@"12222222 %@",self.a);
    }];
}

点击按钮,动画效果会在最后恢复到最初始的位置,是否有人能够简单解答一下,为什么[self.view addSubview:[[UIView alloc] init]]; 会造成这个问题

为情所困
为情所困

全員に返信(1)
黄舟

レイアウトに自動レイアウトを使用する場合、対応するビューをアニメーション化する必要がある場合は、フレームではなくレイアウトも変更する必要があります。

いいねを押す +0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!