我在应用程序中遇到了一些问题。当我在一个有很多图标(UIViews)的屏幕上,每个图标都运行一个动画时,就会出现这个错误。这个画面会让人想起跳板画面,动画效果也很相似。
因此,如果我按下主页按钮,应用程序不会转到后台,我也不能做任何事情。连电源按钮都不能用。图标还在继续抖动。
如果我删除对标签创建方法的调用,这种情况就不会发生。
有什么建议吗?
谢谢!
动画方法(摘自Three20接口):
- (void)wobble {
static BOOL wobblesLeft = NO;
if (isEditing)
{
CGFloat rotation = (kWobbleRadians * M_PI) / 180.0;
CGAffineTransform wobbleLeft = CGAffineTransformMakeRotation(rotation);
CGAffineTransform wobbleRight = CGAffineTransformMakeRotation(-rotation);
[UIView beginAnimations:nil context:nil];
NSInteger i = 0;
NSInteger nWobblyButtons = 0;
for(Icon *ic in iconList)
{
++nWobblyButtons;
i++;
if (i % 2)
{
ic.transform = wobblesLeft ? wobbleRight : wobbleLeft;
} else {
ic.transform = wobblesLeft ? wobbleLeft : wobbleRight;
}
}
if (nWobblyButtons >= 1)
{
[UIView setAnimationDuration:kWobbleTime];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(wobble)];
wobblesLeft = !wobblesLeft;
} else {
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[self performSelector:@selector(wobble) withObject:nil afterDelay:kWobbleTime];
}
[UIView commitAnimations];
}
}标签创建
-(void)layoutLabel
{
// If title isn`t builded.
if(_lblName == nil)
{
// Create new label.
_lblName = [[UILabel alloc] initWithFrame:CGRectMake(LABEL_POS_X,
LABEL_POS_Y,
LABEL_WIDTH,
LABEL_HEIGHT)];
// Clear the background.
[_lblName setBackgroundColor:[UIColor clearColor]];
// Sets the font.
[_lblName setFont:[UIFont fontWithName:@"Helvetica-Bold" size:11.3]];
[_lblName setAdjustsFontSizeToFitWidth:NO];
// Sets text color
[_lblName setTextColor:[UIColor whiteColor]];
// Adjust the number of lines.
[_lblName setNumberOfLines:2];
// Adjust the aligment to center.
[_lblName setTextAlignment:UITextAlignmentCenter];
// Adjust shadow like the springboad`s icons.
_lblName.layer.shadowOpacity = 1.0;
_lblName.layer.shadowRadius = 0.8;
_lblName.layer.shadowColor = [[UIColor blackColor] CGColor];
_lblName.layer.shadowOffset = CGSizeMake(0, 1.2);
// Add label to container.
[self addSubview:_lblName];
}
}发布于 2012-05-22 03:28:09
问题是:
对于每个图标,我有许多子视图,因此,在动画时间,每个图标的计算导致代码变慢。
所以,我找到了一些光来解决这个问题。我构建了相同的图标结构,但之后,我用下面的代码合并了UIImage中的所有内容。
+ (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}这使我的FPS从~15增加到60。
遵循我找到的Link的一些帮助
发布于 2012-05-20 01:36:02
阴影的动画效果一点也不好。在动画过程中禁用它们,并在动画完成后重新打开它们。
我在使用阴影动画时没有冻结,但性能是不可接受的急转直下。根据我的经验,尝试动画任何有阴影的东西都会产生不可接受的结果。
https://stackoverflow.com/questions/10658675
复制相似问题