UIImageView 角半径和 CGrect
我正在制作一款游戏,你触碰一个球,然后必须通过一些栏杆。然而,球不得接触这些横杆。球是一个 gif 图像。我的问题是:球是圆形,但 uiimageview 是方形。如果 uiimageview 的角(不是球图像)接触到条形,则表示球接触到了条形。即使我这样做也
// imageMover is the UIImageView
// the radius of the ball is 30.0
[[imageMover layer] setMasksToBounds:YES];
[[imageMover layer] setCornerRadius:30.0f];
没有改变。我想我需要一个圆形框架(CGRect),但是如何“创建”圆形框架?
I am making a game where you touch a ball and have to pass some bars. However the ball must not touch those bars. The ball is a gif-image. My problem is: The ball is a circle but the uiimageview is a square. If the corners of the uiimageview (which is not the ball image) touch the bars it says that the ball touches the bar. even if I do that
// imageMover is the UIImageView
// the radius of the ball is 30.0
[[imageMover layer] setMasksToBounds:YES];
[[imageMover layer] setCornerRadius:30.0f];
there is no change. I think i need a rounded frame (CGRect) but how do you "create" a rounded frame?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个
try this
您无法创建圆形框架。
但您可以创建带有圆角的 UIImageView。
导入 QuartzCore (#import ) 标头并使用 UIImageView 的 Layer 属性。
有关详细信息,请参阅 CALayer 类参考:
https://developer.apple.com/library /mac/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html
谢谢!
you cannot creat a rounded frame.
but you can create an UIImageView with rounded corners.
Import the QuartzCore (#import ) header and play with the layer property of the UIImageView.
see the CALayer class reference for detail:
https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html
thanks!