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

查看:25
本文介绍了“掩饰"动画?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?

推荐答案

我没有尝试过这个性能,但你可以使用核心动画层作为蒙版.您可以定义要在 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天全站免登陆