嗨,我有一個uislider,它改變了uiimageview中的圖像。第一次它很好地工作,沒有任何延遲。但是,當我點擊按鈕發佈(有一個模式視圖打開),並關閉模式視圖(這是第二次)uiimageview延遲顯示圖像。我找不到爲什麼它會變慢:(第二次粘貼UISlider
-(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,但圖片很慢,然後第一次。
這是相當多的代碼要在滑塊回調中運行。請記住,這種委託方法每秒可以調用數百次。 – coneybeare
是的,你是對的,但(作爲noob)我不能在全局定義數組,因此這些行將消失。 –