2011-09-08 62 views
0

嗨,我有一個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,但圖片很慢,然後第一次。

+1

這是相當多的代碼要在滑塊回調中運行。請記住,這種委託方法每秒可以調用數百次。 – coneybeare

+0

是的,你是對的,但(作爲noob)我不能在全局定義數組,因此這些行將消失。 –

回答

-1

我的alertview使應用程序(滑塊和圖像)變得更慢,所以我刪除它,它工作得很好。

2

那麼,我想說,在這裏讓你更加敏感的第一步是從這個委託方法中刪除所有的對象分配和不必要的邏輯。可以每秒調用滑塊委託方法100次以上(如果它設置爲連續的),並且您應該真正使用它來僅更新ivars並執行最少的邏輯。這很可能是你拖延的根本原因。至於爲什麼它第二次發生,也許你在複製滑塊設置viewWillAppear,所以在模態之後,委託方法被調用兩次。

+0

感謝提示隊友我檢查我不使用wiewwillappear滑塊也是iboutlet,但我試圖minimaze函數中的代碼我會報告給你,如果它將更快asap –

+0

nop隊友其仍然是我清理最的代碼,但仍然是第二次堅持。 –

+0

然後,也許你可以發佈代碼設置你的滑塊,也是所有滑塊相關的代碼。 – coneybeare