【发布时间】:2011-12-20 00:33:48
【问题描述】:
我正在使用陀螺仪来处理旋转。对于我旋转 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;
}
陀螺仪会给我一个值,我会计算图像的高度。之后我调用这个函数来重绘蒙版和图像。因此,如果我滚动设备,图像会向上或向下。
【问题讨论】:
-
显示有问题的代码,以便我们可以使用。
-
记住 Apple 示例应用程序的目的,这通常是最简单的展示。我发现
CAReplicatorLayer的性能非常好,如果可以的话尝试使用它。
标签: ios core-graphics gradient gyroscope