【问题标题】:Curve-inside UIView top borderCurve-inside UIView 上边框
【发布时间】:2015-04-27 02:56:05
【问题描述】:

我想像这样在 UIView 的上边框内弯曲,

我尝试了很多方法,比如 UIBezierPath 等。

需要帮助。

【问题讨论】:

  • 再次尝试 UIBezierPath ;)
  • 如果 UIBezierPath 不能帮助创建类似上述曲线的图像并将其设置为视图的背景。
  • @Kampai:实际上我正在使用 CAShapeLayer。有多个层,所以我正在寻找一些 UIBezierPath 解决方案。
  • 好吧,我想通了。动画整个视图。在动画期间,将 self.view.origin.y 更改为下方。现在完成设置 self.view.origin.y 到它的原始位置。 NSInteger 选项 = UIViewAnimationCurveEaseInOut; orgRect = self.frame; CGRect tempRect = orgRect; tempRect.origin.y = tempRect.origin.y+20; [UIView animateWithDuration:0.05 delay:0.0 usingSpringWithDamping:0.5 initialSpringVelocity:0.5 options:option animations:^{ self.frame = tempRect; } 完成:^(布尔标志){ self.frame = orgRect; }];

标签: ios objective-c xcode cocoa-touch core-animation


【解决方案1】:

您可以使用UIBezierPath 做到这一点,看看这个answer

UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:_backgroundImageView.bounds 
                             byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) 
                                   cornerRadii:CGSizeMake(3.0, 3.0)];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
_backgroundImageView.layer.mask = maskLayer;
[maskLayer release];

有了这个,我们可以将圆角绘制到视图的任何一侧。 但是如果你想画圆边,最好拍一张背景图来查看。

【讨论】:

  • 谢谢,但这个答案是针对 UIView 的圆角。
  • 同意这是一个不正确的答案,而不是 @Hxb 正在寻找的内容
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多