3

我目前正在編寫iOS應用程序,並且不喜歡UIImagePickerController消失的速度。在iOS中通過UIImagePickerController加載UIActivityIndi​​cator

我打電話給[self dismissModalViewControllerAnimated:YES];即時我在- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;裏面,然而imagePicker需要一些時間才能消失,在一些照片上足夠長,以至於應用程序看起來會凍結給用戶。

我想到的一個解決方案就是拋出一個UIImagePickerController的UIActivityIndi​​cator infront,但我還沒有想出一種方法來實現這一點。

謝謝!

編輯:關於如何更快地保存UIImages的任何提示也會有幫助,我相信。比如一種非同步的方式。

回答

4

有與雷Wenderlich大中央調度和代碼塊這樣一個偉大的教程: http://www.raywenderlich.com/1888/how-to-create-a-simple-iphone-app-tutorial-part-33 您也可以與作業隊列和performSelector做到這一點:onThread:withObject:waitUntilDone:如果塊是可怕的你。

基本上,這個想法是在主線程上做最少量的實際工作,因爲這是繪製UI的地方。以下是RW的解決方案,狀態部分已註釋掉。這就是你放置活動指標的地方。

- (IBAction)addPictureTapped:(id)sender { 
    if (self.picker == nil) { 

     // 1) Show status 
     //[SVProgressHUD showWithStatus:@"Loading picker..."]; 

     // 2) Get a concurrent queue form the system 
     dispatch_queue_t concurrentQueue = 
     dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 

     // 3) Load picker in background 
     dispatch_async(concurrentQueue, ^{ 

      self.picker = [[UIImagePickerController alloc] init]; 
      self.picker.delegate = self; 
      self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
      self.picker.allowsEditing = NO;  

      // 4) Present picker in main thread 
      dispatch_async(dispatch_get_main_queue(), ^{ 
       [self.navigationController presentModalViewController:picker animated:YES];  
       [SVProgressHUD dismiss]; 
      }); 

     });   

    } else {   
     [self.navigationController presentModalViewController:picker animated:YES];  
    } 
} 
相關問題