I can't figure this out... I'm playing with
我无法弄明白......我正在玩
-[UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:]
as such:
- [UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:]如下:
bezierPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(10, 10, 80, 80)
byRoundingCorners:(UIRectCornerBottomLeft)
cornerRadii:CGSizeMake(20, 20)];
And it works as expected. But if I replace cornerRadii:CGSizeMake(20, 20) with, say, cornerRadii:CGSizeMake(20, 5)
or CGSizeMake(20, 40)
, there's no difference.
它按预期工作。但是如果我用cornerRadii:CGSizeMake(20,5)或CGSizeMake(20,40)替换cornerRadii:CGSizeMake(20,20),那就没有区别了。
Why is cornerRadii CGSize
and not CGFloat
then? What is CGSize.height
for?
为什么cornerRadii CGSize而不是CGFloat呢?什么是CGSize.height?
Any ideas and advice will be greatly appreciated :)
任何想法和建议将不胜感激:)
3 个解决方案
#1
6
I can now confirm that this is a bug introduced after iOS 6. I have an old 4s running iOS 6.1. On that machine, this code:
我现在可以确认这是iOS 6之后引入的一个错误。我有一个运行iOS 6.1的旧4。在那台机器上,这段代码:
path = [UIBezierPath bezierPathWithRoundedRect: bounds
byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii: CGSizeMake(bounds.size.width/2, bounds.size.width/6)
];
Creates a rounded rectangle with the corners oval-shaped. The curve is much more gradual on the top part of the curve, and much sharper on the sides, as you would expect:
创建一个圆角矩形,边角为椭圆形。曲线顶部的曲线更加渐进,两侧更加锐利,如您所料:
This is the iOS 6.1 image, with the corners as they should be:
这是iOS 6.1图像,应该是角落:
And here is what the same code looks like when run from iOS 8.1.2:
以下是从iOS 8.1.2运行时相同的代码:
It appears that on iOS >=7.0, it ignores the height of the specified radius and uses the width value for both the height and the width of the corner ovals, which forces them to always be quarter circles.
看起来在iOS> = 7.0时,它会忽略指定半径的高度,并使用宽度值来表示角椭圆的高度和宽度,这会强制它们始终为四分之一圆。
I've logged a bug on apple's bug reporter system. We'll see what they say. I suggest everybody else who's seeing this problem report a bug also. The more reports they get, the more likely they are to fix it.
我在苹果的bug报告系统上记录了一个错误。我们会看到他们说的话。我建议所有看到此问题的人也报告错误。他们获得的报告越多,他们就越有可能修复它。
#2
3
Well, after further tests I finally found that it seems to be an iOS 7 bug. The same code on iOS 6 simulator draws properly, as expected. however, both iOS 7 simulator and iOS 7 device have this issue and draw improperly.
好吧,经过进一步的测试,我终于发现它似乎是一个iOS 7的bug。正如预期的那样,iOS 6模拟器上的相同代码正确绘制。但是,iOS 7模拟器和iOS 7设备都存在此问题并且绘制不正确。
I'll file a bug report, unless someone proves me wrong and there is something I am missing.
我会提交一份错误报告,除非有人证明我错了,而且我有些遗漏。
#3
1
The CGSize
parameter is to allow the corner radii on the the horizontal and vertical planes to be different. i.e. a non-symmetrical corners.
CGSize参数允许水平和垂直平面上的角半径不同。即一个非对称的角落。
Try turning on different corners and using different values to see what happens.
尝试打开不同的角落并使用不同的值来查看会发生什么。
#1
6
I can now confirm that this is a bug introduced after iOS 6. I have an old 4s running iOS 6.1. On that machine, this code:
我现在可以确认这是iOS 6之后引入的一个错误。我有一个运行iOS 6.1的旧4。在那台机器上,这段代码:
path = [UIBezierPath bezierPathWithRoundedRect: bounds
byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii: CGSizeMake(bounds.size.width/2, bounds.size.width/6)
];
Creates a rounded rectangle with the corners oval-shaped. The curve is much more gradual on the top part of the curve, and much sharper on the sides, as you would expect:
创建一个圆角矩形,边角为椭圆形。曲线顶部的曲线更加渐进,两侧更加锐利,如您所料:
This is the iOS 6.1 image, with the corners as they should be:
这是iOS 6.1图像,应该是角落:
And here is what the same code looks like when run from iOS 8.1.2:
以下是从iOS 8.1.2运行时相同的代码:
It appears that on iOS >=7.0, it ignores the height of the specified radius and uses the width value for both the height and the width of the corner ovals, which forces them to always be quarter circles.
看起来在iOS> = 7.0时,它会忽略指定半径的高度,并使用宽度值来表示角椭圆的高度和宽度,这会强制它们始终为四分之一圆。
I've logged a bug on apple's bug reporter system. We'll see what they say. I suggest everybody else who's seeing this problem report a bug also. The more reports they get, the more likely they are to fix it.
我在苹果的bug报告系统上记录了一个错误。我们会看到他们说的话。我建议所有看到此问题的人也报告错误。他们获得的报告越多,他们就越有可能修复它。
#2
3
Well, after further tests I finally found that it seems to be an iOS 7 bug. The same code on iOS 6 simulator draws properly, as expected. however, both iOS 7 simulator and iOS 7 device have this issue and draw improperly.
好吧,经过进一步的测试,我终于发现它似乎是一个iOS 7的bug。正如预期的那样,iOS 6模拟器上的相同代码正确绘制。但是,iOS 7模拟器和iOS 7设备都存在此问题并且绘制不正确。
I'll file a bug report, unless someone proves me wrong and there is something I am missing.
我会提交一份错误报告,除非有人证明我错了,而且我有些遗漏。
#3
1
The CGSize
parameter is to allow the corner radii on the the horizontal and vertical planes to be different. i.e. a non-symmetrical corners.
CGSize参数允许水平和垂直平面上的角半径不同。即一个非对称的角落。
Try turning on different corners and using different values to see what happens.
尝试打开不同的角落并使用不同的值来查看会发生什么。