我的视图控制器中存在动画问题。我有两个UIViews
:蓝色视图和绿色视图。蓝色视图在绿色视图顶部。在绿色视图中,我有一个动态正弦波UIView
和另一个名为“recordingIndicatorView”的UIView
,它由一个实现了闪烁动画的文本标签组成。当我向上滑动蓝色视图时,绿色视图显示,正弦波视图开始动画,recordingIndicatorView开始闪烁。当我向下滑动蓝色视图时,动画结束,正弦视图和recordingIndicatorView被隐藏。
但是,如果我向上滑动蓝色视图,向下滑动,然后快速向上滑动蓝色视图,闪烁的动画会被甩掉并开始更快地闪烁。
- (IBAction)handleUpSwipe:(UISwipeGestureRecognizer *)recognizer
{
if(viewIsUp == NO)
{
[self.sineWave animateWave];
[self showSine];
[UIView animateWithDuration:.25 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
[self moveViewsUp];
} completion:^(BOOL finished){
}];
stopBlinking = NO;
[self.recordingIndicatorView setHidden:NO];
[self flashOn:self.recordingIndicatorView];
}
}
- (IBAction)handleDownSwipe:(UISwipeGestureRecognizer *)recognizer
{
if(viewIsUp == YES)
{
[self stopRecording];
if(self.panedView.frame.origin.y <0)
{
[UIView animateWithDuration:.25 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
[self hideSine];
[self moveViewsDown];
} completion:^(BOOL finished){
[self.sineWave.layer removeAllAnimations];
}];
}
}
}
-(void) stopRecording
{
stopBlinking = YES;
[self hideSine];
[self.recordingIndicatorView setHidden:YES];
}
- (void)flashOff:(UIView *)v
{
[UIView animateWithDuration:.5 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^ {
self.recordingIndicatorView.alpha = 0.01;
} completion:^(BOOL finished) {
if(stopBlinking == NO)
{
[self flashOn:self.recordingIndicatorView];
}
}];
}
- (void)flashOn:(UIView *)v
{
[UIView animateWithDuration:.5 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^ {
self.recordingIndicatorView.alpha = 1;
} completion:^(BOOL finished) {
[self flashOff:self.recordingIndicatorView];
}];
}
-(void) moveViewsDown
{
if(viewIsUp)
{
self.panedView.frame = CGRectOffset( self.panedView.frame, 0, 274);
self.sineWave.frame = CGRectOffset(self.sineWave.frame, 0, 246);
self.micImageView.frame = CGRectOffset(self.micImageView.frame, 0, 85.5);
viewIsUp = NO;
}
}
-(void) moveViewsUp
{
if(!viewIsUp)
{
self.panedView.frame = CGRectOffset(self.panedView.frame, 0, -274);
self.sineWave.frame = CGRectOffset(self.sineWave.frame, 0, -246);
self.micImageView.frame = CGRectOffset(self.micImageView.frame, 0, -85.5);
viewIsUp = YES;
}
}
答案 0 :(得分:0)
我认为你的闪烁动画被添加了不止一次。 viewIsUp标志可能有些混乱。这是我能在没有其他代码的情况下找到的。并且尽量不要在块中使用self这是一个坏习惯并导致隐藏的错误和内存泄漏,使用弱自我,比如:
__weak typeof(self) wSelf = self;
[UIView animateWithDuration:.25 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
[wSelf hideSine];
[wSelf moveViewsDown];
} completion:^(BOOL finished){
[wSelf.sineWave.layer removeAllAnimations];
}];