我有一个 UIView 在我的应用程序中充当徽章,按下按钮后,徽章应该会闪烁,然后做一个漂亮的挤压和拉伸动画。该动画在 iPhone 4、iPhone 4s 和 iPhone 5 上完美运行,但 8GB iPod touch(第 4 代)iOS 5.1.1 的卡顿效果非常糟糕。
popWithDuration: 方法会导致卡顿,而 resetCount 方法会导致视图大小爆炸。想知道是否有人知道任何修复或解决方法。
下面是相关方法,类是UIView的子类。
- (void)popWithDuration:(CGFloat)duration
{
if(self.canAnimateLikedNumber)
{
if(self.waitingToReset){
[self resetCount];
return;
}
else
self.canAnimateLikedNumber = FALSE;
CGAffineTransform stretchTransform = CGAffineTransformMakeScale(1.5,1.5);
CGAffineTransform squashTransform = CGAffineTransformMakeScale(1.0,1.0);
[UIView animateWithDuration:duration delay:0.0f options:UIViewAnimationOptionLayoutSubviews animations:^{
[self setAlpha:1.0f];
[self setTransform:stretchTransform];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.2f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState animations:^{
[self setTransform:squashTransform];
} completion:^(BOOL finished) {
self.canAnimateLikedNumber = TRUE;
if(self.waitingToReset){
[self resetCount];
return;
}
}];
}];
}
}
- (void) resetCount
{
if([NSString isValid: self.savedCountLabel.text] || (!self.hidden && self.superview))
{
if(self.canAnimateLikedNumber)
{
self.canAnimateLikedNumber = FALSE;
CGSize defaultSize = [NotificationBadge DefaultBadgeSize];
CGRect originalRect = CGRectMake(self.frame.origin.x, self.frame.origin.y, defaultSize.width, defaultSize.height);
[UIView animateWithDuration:0.2 delay:0.0f options:UIViewAnimationOptionLayoutSubviews animations:^{ //squash and stretch
[self setTransform:CGAffineTransformMakeScale(2, 2)];
}
completion:^(BOOL finished)
{
[UIView animateWithDuration:0.4 delay:0.0f options:UIViewAnimationOptionLayoutSubviews animations:^{
[self setTransform:CGAffineTransformMakeScale(0.0,0.0)];
[self setAlpha:0.0f];
}
completion:^(BOOL finished)
{
[self setHidden:TRUE];
[self setTransform:CGAffineTransformMakeScale(1.0,1.0)];
[self setFrame:originalRect];
[self.savedCountLabel setText:@"0"];
[self.savedCountLabel setFrame:CGRectMake(NOTIFICATION_LABEL_INSETS.left, NOTIFICATION_LABEL_INSETS.top, defaultSize.width - NOTIFICATION_LABEL_INSETS.left - NOTIFICATION_LABEL_INSETS.right, defaultSize.height - NOTIFICATION_LABEL_INSETS.top - NOTIFICATION_LABEL_INSETS.bottom)];
self.canAnimateLikedNumber = TRUE;
self.waitingToReset = FALSE;
}];
}];
}
else
{
self.waitingToReset = TRUE;
}
}
}