在视网膜iPad上应用图层蒙版可隐藏所有内容

时间:2012-11-09 13:08:44

标签: ios ipad uiview mask cgpath

我有一个UIView,我应用了一个图层蒙版。除了视网膜iPad之外,它在每个设备上都能很好地工作。在视网膜iPad上,正在屏蔽的视图不会显示。如果我取下面罩,视图会显示在视网膜iPad上。

面具非常简单。除了从底部边缘取出的小三角形之外,它显示整个视图。

contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] applicationFrame].size.width, [[UIScreen mainScreen] applicationFrame].size.height - 50.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
CGMutablePathRef path = CGPathCreateMutable();
float triangleDepth = 10;
CGPathMoveToPoint(path, NULL, 0, 0);
CGPathAddLineToPoint(path, NULL, contentView.frame.size.width, 0);
CGPathAddLineToPoint(path, NULL, contentView.frame.size.width, contentView.frame.size.height);
CGPathAddLineToPoint(path, NULL, (contentView.frame.size.width / 2.0) + triangleDepth, contentView.frame.size.height);
CGPathAddLineToPoint(path, NULL, (contentView.frame.size.width / 2.0), contentView.frame.size.height - triangleDepth);
CGPathAddLineToPoint(path, NULL, (contentView.frame.size.width / 2.0) - triangleDepth, contentView.frame.size.height);
CGPathAddLineToPoint(path, NULL, 0, contentView.frame.size.height);
CGPathCloseSubpath(path);
[maskLayer setPath:path];
CGPathRelease(path);
contentView.layer.mask = maskLayer;
contentView.clipsToBounds = NO;
[self.view addSubview:contentView];

这个代码适用于每个设备,那么视网膜iPad会有什么不同之处呢?

1 个答案:

答案 0 :(得分:1)

这只是iOS模拟器的一个问题。我终于在视网膜iPad上尝试了代码,一切正常。