ios - UIImageView IOS中间的透明圆圈
<p><p>我需要使 UIImageView 在中间位置透明(圆环..见附图)<img src="/image/mMKE1.png" alt="enter image description here"/> <br/>
我应该能够通过那个中间圆圈看到 UIImageView 的后面 subview ...我尝试了 CAShapeLayer ..但我看不到 UIImageView 的后面 subview ..请帮助我..对不起我的英语.... </p>
<pre><code> CAShapeLayer *circleLayer = ;
// Give the layer the same bounds as your image view
.size.width,
[((UIImageView *)view) bounds].size.height)];
// Position the circle anywhere you like, but this will center it
// In the parent layer, which will be your image view's root layer
[circleLayer setPosition:CGPointMake(100,
100)];
// Create a circle path.
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:
CGRectMake(100.0f, 100.0f, 50.0f, 50.0f)];
// Set the path on the layer
];
// Set the stroke color
CGColor]];
// Set the stroke line width
;
// Add the sublayer to the image view's layer tree
;
[[((UIImageView *)view) layer] addSublayer:circleLayer];
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>一种方法是这样的。我的主图像有一个 ImageView ,还有一个名为 BlackCircle 的图像,它只是一个 40x40 的黑色圆圈(我在 Pixen 应用程序中制作的)。 action 方法使主图像在与黑色圆圈重叠的地方变为透明,我已将其放置在主图像的中心:</p>
<pre><code>@interface ViewController ()
@property (weak,nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation ViewController
-(void)viewDidLoad {
;
self.imageView.image = ;
self.imageView.backgroundColor = ;
}
-(IBAction)createAlphaClippedImage:(id)sender {
UIImage *circleImage = ;
UIImage *mainImage = ;
UIGraphicsBeginImageContextWithOptions(mainImage.size, NO, 0.0);
CGRect imageRect = CGRectMake(0.0f, 0.0f, mainImage.size.width, mainImage.size.height);
CGRect centerCircleRect = CGRectMake(mainImage.size.width/2.0 - circleImage.size.width/2.0, mainImage.size.height/2.0 - circleImage.size.height/2.0,circleImage.size.width,circleImage.size.height);
;
;
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.imageView.image = image;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - UIImageView IOS中间的透明圆圈,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/20064115/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/20064115/
</a>
</p>
页:
[1]