UIimageview适合圆形

Phi*_*hil 0 iphone collision uiimageview ios

我有一个UIImageview包含一个圆圈(障碍物),然后另一个UIImageview包含另一个图像(我的角色).当我的圈子击中我的角色时,游戏结束.

我的问题发生在游戏结束时,角色触摸UIImageview我的圆圈所在的方框,而不是UIImageview方框内的圆圈.

我能想到的解决方案是:

  • 使UIImageview圆形适合我的圆圈.
  • 以某种方式检测我的角色像素和圆形像素之间的碰撞而不是UIImageviews.

真的很感激帮助和想法.我是xcode的初学者.

谢谢!

Bha*_*esh 6

Couple of different techniques:

1)UIView#layer.cornerRadius - Super simple to implement, just set that one property. But really bad for scrolling elements like table views.

2)UIImageView as a mask - Also easy to implement. Basically make a square image with a transparent circle in the middle and slap it on top of your view with a new UIImageView. If your circle design has some reflections or styling, this might make your life easier.

3)Custom drawing - Make a UIView subclass and override drawRect to draw your image and clip it to a circular path.

Hope that helps!

EDIT:

You can read this answers.

1)Fill an UIBezierPath with a UIImage

2)iOS:反向UIBezierPath(bezierPathWithOvalInRect)

3)如何在iPhone SDK中将方形图像蒙版成圆角图像?