2011-12-20 55 views
-1

我正在使用陀螺儀來處理旋轉。對於我旋轉iPad的每個學位,我都應該在屏幕上重新繪製圖像以更改蒙版的高度。在使用漸變蒙版重繪圖像時IOS上的性能問題

但重繪會停止陀螺儀。

我能爲這種情況做些什麼?

編輯代碼添加

- (UIImage *)reflectedImage:(UIImageView *)fromImage withHeight:(NSUInteger)height 
{ 
CGImageRef gradientMaskImage = CreateGradientImage(1, height); 

CGImageRef masked = CGImageCreateWithMask([fromImage.image CGImage], gradientMaskImage); 
CGImageRelease(gradientMaskImage); 

UIImage *theImage = [UIImage imageWithCGImage:masked]; 

return theImage; 
} 

陀螺會給我一個值,我計算圖像的高度。之後,我稱這個函數來重畫面具和圖像。所以,如果我滾動設備,圖像會被遮擋或盲目下拍。

+0

顯示他有問題的代碼,所以我們有一些工作。 – WrightsCS 2011-12-20 04:35:51

+0

請記住蘋果示例應用程序的目的,這通常是最簡單的展示。我發現'CAReplicatorLayer'的性能非常好,儘可能使用它。 – 2013-06-07 22:03:33

回答

1

您可以在後臺線程中重繪圖像。當圖像準備好時,更新主線程上的UI。

static dispatch_queue_t background_queue; 
- (void)updateImage { 
    if (background_queue == nil){ 
     background_queue = dispatch_queue_create("com.myappname.myIdentifier", 0); 
    } 

    dispatch_async(background_queue,^{ // render the image in the background thread 
    UIImage * theImage = [self reflectedImage:fromImage withHeight:height]; 
    dispatch_sync(dispatch_get_main_queue(), ^{ 
     imageView.image = theImage; // Update the imageview in the main thread 
    }); 
    }); 
} 

編輯:代碼修復

+0

有沒有實時解決方案?因爲我猜這會是異步的。 – Burak 2011-12-20 20:37:38

+0

圖像將以正確的順序進行渲染和顯示(即幀(t)將在所有t的幀(t + 1)之前呈現。如果您需要更快的解決方案,那麼您必須找到一些方法來優化或者可能生成並緩存所有可能的圖像(360?) – lorean 2011-12-20 20:49:30

+0

其實我只是想改變漸變層的高度,所以我不應該重繪所有的圖像,但我該怎麼做呢? – Burak 2011-12-20 20:55:46