Why is cornerRadii parameter of CGSize type in -[UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:]?

故事扮演 提交于 2019-11-29 00:21:23

问题


I can't figure this out... I'm playing with

-[UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:] as such:

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.

Why is cornerRadii CGSize and not CGFloat then? What is CGSize.height for?

Any ideas and advice will be greatly appreciated :)


回答1:


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:

  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:

And here is what the same code looks like when run from 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.

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.




回答2:


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.

I'll file a bug report, unless someone proves me wrong and there is something I am missing.




回答3:


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.

Try turning on different corners and using different values to see what happens.



来源:https://stackoverflow.com/questions/18880919/why-is-cornerradii-parameter-of-cgsize-type-in-uibezierpath-bezierpathwithroun

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!