-1

我正在使用陀螺仪来处理旋转。对于我旋转 iPad 的每一度,我应该在屏幕上重新绘制图像以更改蒙版的高度。

但是重绘会停止陀螺仪。

这种情况我能做些什么?

添加了编辑代码

- (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;
}

陀螺仪会给我一个值,我计算图像的高度。之后我调用这个函数来重绘蒙版和图像。因此,如果我滚动设备,图像会变暗或变暗。

4

1 回答 1

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
     });
  });
}

编辑:代码修复

于 2011-12-20T20:06:03.977 回答