0

我正在做一个游戏,你触摸一个球并且必须通过一些酒吧。然而,球不得接触那些横杆。球是一个 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),但你如何“创建”一个圆角框架?

4

2 回答 2

0

尝试这个

imageMover.layer.shouldRasterize = YES;

imageMover.clipsToBounds = YES;

imageMover.layer.cornerRadius = 10.0f; // what number you want
于 2014-03-09T13:45:29.793 回答
0

您无法创建圆形框架。

但您可以创建一个带有圆角的 UIImageView。

导入 QuartzCore (#import) 标头并使用 UIImageView 的 layer 属性。

    imageMover.layer.cornerRadius = yourRadius;
    imageMover.clipsToBounds = YES;

有关详细信息,请参阅 CALayer 类参考: https ://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html

谢谢!

于 2014-03-09T14:36:19.127 回答