UISlider第二次卡住
你好,我有一个 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:
我取消了一些动画,滑块恢复到原来的速度,但现在图片粘在滑块上,但图片比第一次慢。
Hi i have a uislider that changes the images in uiimageview.At first time it works great there is no delay . But when i click the button to publish (there is a modal view that opens) and close the modal view (this is the second time) the uiimageview delays that shown the images.i cant find why it gets slower:(
-(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];
}
this is my code if u can see why performance decrease in the second time i slide the slider pls tell me
edit 1:
i cancel some animations and slider get back to its speed but now the pictures are sticking slider okey but pictures are slow then the first time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我想说,要使该方法更具响应性,第一步是从该委托方法中删除所有对象分配和不必要的逻辑。滑块委托方法每秒可以调用超过 100 次(如果将其设置为连续),您实际上应该使用它来仅更新 ivars 并执行最少的逻辑。这很可能是导致您延误的根本原因。至于为什么第二次发生这种情况,可能是您在 viewWillAppear 上复制了滑块设置,因此在模式之后,委托方法被调用了两倍。
Well, I would say that your first step here to making this method more responsive is to remove all object allocations and unnecessary logic from this delegate method. The slider delegate method can be called over 100 times a second (if it is setup as continuous) and you should really be using it to only update ivars and perform minimal logic. This is most likely the root cause of your delays. As for why it is happening on the second time around, perhaps you are duplicating slider setup on your
viewWillAppear
, so after the modal, the delegate method is called twice as much.我的警报视图使应用程序(滑块和图像)变慢,所以我将其删除,它工作得很好。
My alertview makes the application (slider and images) goes slower so i remove it and it work just fine.