嗨我有一个uislider改变uiimageview中的图像。第一次它工作得很好没有延迟。但是当我点击按钮发布(有一个打开的模态视图)并关闭模态视图(这是第二次)时,uiimageview会延迟显示图像。我无法找到它变慢的原因:(
-(IBAction)sliderSlide:(UISlider *)aSlider {
float f=slider.value;
NSString *show=[NSString stringWithFormat:@"%.0f %%",f];
label2.text=show;
NSString *show1=[NSString stringWithFormat:@"%.0f",f];
imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"/Smiley_000%@.png", show1]];
float slid=slider.value;
if(slid>99)
{
[imageView1 setHidden:NO];
[imageView2 setHidden:YES];
NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Smiley_00099.png"];
imageView.image = [UIImage imageWithContentsOfFile:fullpath];
secondarray=[NSArray arrayWithObjects:
[UIImage imageNamed:@"Rays_00000.png"],
[UIImage imageNamed:@"Rays_00001.png"],
[UIImage imageNamed:@"Rays_00002.png"],
[UIImage imageNamed:@"Rays_00003.png"],
[UIImage imageNamed:@"Rays_00004.png"],
[UIImage imageNamed:@"Rays_00005.png"],
[UIImage imageNamed:@"Rays_00006.png"],
[UIImage imageNamed:@"Rays_00007.png"],
[UIImage imageNamed:@"Rays_00008.png"],
[UIImage imageNamed:@"Rays_00009.png"],
nil];
imageView1.animationImages = secondarray;
// How many seconds it should take to go through all images one time.
imageView1.animationDuration = 0.5;
// How many times to repeat the animation (0 for indefinitely).
imageView1.animationRepeatCount = 0;
[imageView1 startAnimating];
}
else if (slid<1)
{
[imageView2 setHidden:NO];
[imageView1 setHidden:YES];
NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Smiley_0000.png"];
imageView.image = [UIImage imageWithContentsOfFile:fullpath];
firstarray=[NSArray arrayWithObjects:
[UIImage imageNamed:@"Teardrop_00000.png"],
[UIImage imageNamed:@"Teardrop_00001.png"],
[UIImage imageNamed:@"Teardrop_00002.png"],
[UIImage imageNamed:@"Teardrop_00003.png"],
[UIImage imageNamed:@"Teardrop_00004.png"],
[UIImage imageNamed:@"Teardrop_00005.png"],
[UIImage imageNamed:@"Teardrop_00006.png"],
[UIImage imageNamed:@"Teardrop_00007.png"],
[UIImage imageNamed:@"Teardrop_00008.png"],
[UIImage imageNamed:@"Teardrop_00009.png"],
[UIImage imageNamed:@"Teardrop_00000.png"],
[UIImage imageNamed:@"Teardrop_00000.png"],
[UIImage imageNamed:@"Teardrop_00000.png"],
[UIImage imageNamed:@"Teardrop_00000.png"],
[UIImage imageNamed:@"Teardrop_00000.png"],
nil];
imageView2.animationImages = firstarray;
// How many seconds it should take to go through all images one time.
imageView2.animationDuration = 0.8;
// How many times to repeat the animation (0 for indefinitely).
imageView2.animationRepeatCount = 0;
[imageView2 startAnimating];
[self.view addSubview:imageView2];
}
else
{
[imageView1 setHidden:YES];
[imageView2 setHidden:YES];
[imageView1 stopAnimating];
[imageView2 stopAnimating];
}
[[NSUserDefaults standardUserDefaults] setFloat:slid forKey:@"slider"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
这是我的代码,如果你能看到为什么第二次滑动滑块时性能下降请告诉我
编辑1:
我取消了一些动画和滑块恢复到它的速度,但现在图片粘贴滑块okey但是图片比第一次慢。
答案 0 :(得分:2)
好吧,我想说,让这个方法更具响应性的第一步就是从这个委托方法中删除所有对象分配和不必要的逻辑。滑块委托方法每秒可调用超过100次(如果它被设置为连续),您应该真正使用它来仅更新ivars并执行最小逻辑。这很可能是您延误的根本原因。至于为什么它会在第二次发生,也许你正在复制viewWillAppear
上的滑块设置,所以在模态之后,委托方法被调用两倍。
答案 1 :(得分:-1)
我的alertview使应用程序(滑块和图像)变慢,所以我删除它,它工作得很好。