简体   繁体   English

剪辑到另一个UIImageView的边界

[英]Clip to bounds of a different UIImageView

I have two UIImageView s, imageView1 and imageView2 . 我有两个UIImageView ,分别为imageView1imageView2 I've set 我已经设定

self.imageView1.clipsToBounds = YES;

but I was wondering if it is possible to set imageView1 to clipToBounds of imageView2 ? 但我想知道是否有可能设置imageView1clipToBoundsimageView2

Not easily. 不容易。 The "right" way to do this would be to use a clipping path on the imageView1 's layer. 做到这一点的“正确”方法是在imageView1的图层上使用剪切路径。 However, you can get the same effect much more easily as follows. 但是,您可以更容易地获得以下相同的效果。

Put imageView1 centered inside a container UIView , and turn that view's clipsToBounds on. imageView1中心的容器内UIView ,并把这种观点的clipsToBounds上。 Then: 然后:

  • If you're using Auto Layout, constrain the container view's size to be equal to the size of imageView2 . 如果您使用的是自动版式,则将容器视图的大小限制为等于imageView2的大小。

  • If you're not using Auto Layout, set the bounds of the container view to the size of imageView2 whenever you calculate layout. 如果你不使用自动布局,置容器中视图的边界,以规模imageView2当你计算布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM