UIImageView 角半径和 CGrect

发布于 2024-12-27 02:20:41 字数 364 浏览 0 评论 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),但是如何“创建”圆形框架?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦中楼上月下 2025-01-03 02:20:41

试试这个

imageMover.layer.shouldRasterize = YES;

imageMover.clipsToBounds = YES;

imageMover.layer.cornerRadius = 10.0f; // what number you want

try this

imageMover.layer.shouldRasterize = YES;

imageMover.clipsToBounds = YES;

imageMover.layer.cornerRadius = 10.0f; // what number you want
因为看清所以看轻 2025-01-03 02:20:41

您无法创建圆形框架。

但您可以创建带有圆角的 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

谢谢!

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.

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

see the CALayer class reference for detail:
https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html

thanks!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文