"掩蔽"动画? iPhone SDK [英] "Masking" an animation? iPhone SDK

查看:117
本文介绍了"掩蔽"动画? iPhone SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究如何在iPhone上屏蔽图像。我遇到了这个解决方案

I have been looking into ways of masking images on the iPhone. I came across this solution

http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html

适用于静止图像。我想要做的是在UIImageView中屏蔽动画。根据我的阅读,我认为这是不可能的,同时也可以实现一个不错的帧速率。

which works great for still images. What I want to do is mask an animation in a UIImageView. From what I have read I don't think this is possible whilst also achieving a decent frame rate.

这导致我问以下是否可能,我可以剪辑UIImageView内的图像?即不重新调整UIImageView的大小到图像的大小,所以有些部分被砍掉了?

This leads me to ask whether the following is possible, could I "clip" the images inside the UIImageView? ie not re-size the UIImageView to the size of the images so some parts are chopped off?

推荐答案

我还没试过这是为了提高性能,但您可以使用Core Animation层作为掩码。您可以定义要在CAShapeLayer中使用的路径并填充形状。然后指定UIImageView图层的图层蒙版。类似于:

I haven't tried this for performance, but you can use a Core Animation layer as a mask. You can define a path to use in a CAShapeLayer and fill the shape. Then specify the layer mask of your UIImageView's layer. Something like:

CGMutablePathRef path = CGPathCreateMutable();
// build the path by adding points
// ...

CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
[shapeLayer setPath:path];
[shapeLayer setFillColor:[[UIColor blackColor] CGColor]];
// Set shape layer bounds and position
// ...

// Set the mask for the image view's layer
[[imageView layer] setMask:shapeLayer];

请注意,这实际上并不像您引用的链接那样创建新图像。这只会创建一个遮罩,用于在图像视图的顶部显示 - 这可能不是您想要的。

Keep in mind that this isn't actually creating a new image as the link you reference does. This just creates a mask for display over top of your image view--which may not be what you want.

这篇关于"掩蔽"动画? iPhone SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆