工作中遇到一個(gè)需求是在一個(gè)頁(yè)面中使用定時(shí)器來(lái)執(zhí)行一個(gè)呼吸動(dòng)畫形式的動(dòng)畫過(guò)程扣孟,但是在呼吸動(dòng)畫過(guò)程中需要view來(lái)響應(yīng)事件费坊,具體實(shí)現(xiàn)貼上代碼:
// 添加定時(shí)器來(lái)實(shí)現(xiàn)呼吸動(dòng)畫效果,leftView與rightView也需要響應(yīng)事件
- (void)addAnimateTimer {
MJWeakSelf
_timer = [NSTimer timerWithTimeInterval:2 block:^(NSTimer * _Nonnull timer) {
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
weakSelf.rightView.transform = CGAffineTransformMakeScale(1.1, 1.1);
weakSelf.leftView.transform = CGAffineTransformMakeScale(0.9, 0.9);
} completion:^(BOOL finished) {
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
weakSelf.leftView.transform = CGAffineTransformIdentity;
weakSelf.rightView.transform = CGAffineTransformIdentity;
} completion:nil];
}];
} repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:_timer forMode:NSDefaultRunLoopMode];
}
動(dòng)畫執(zhí)行效果沒(méi)問(wèn)題犁享,但是我給leftView與rightView兩個(gè)view中都添加了點(diǎn)擊手勢(shì)再来,動(dòng)畫效果實(shí)現(xiàn)后,兩個(gè)view的點(diǎn)擊手勢(shì)無(wú)法響應(yīng)事件闻鉴,所以這里需要設(shè)置一下在動(dòng)畫過(guò)程中需要讓view來(lái)響應(yīng)事件茵乱,重點(diǎn):
執(zhí)行動(dòng)畫參數(shù)中options需要設(shè)置成為UIViewAnimationOptionAllowUserInteraction