UIView 内的 UIButton,带有showTouchWhenHighlighted 辉光被超级视图剪裁

发布于 2024-11-01 02:04:54 字数 459 浏览 0 评论 0原文

我使用的方法可能有点错误,如果是这样,也许有人可以建议......但无论如何,我用于创建响应程序小部件的模式涉及添加一个不可见的 UIButtonTypeCustom 来填充UIView 的边界,以便向任何视图添加向后兼容的按钮行为。对于我的需求,这效果非常好。为了稍微改善使用此混合按钮的用户体验,我将按钮的showsTouchWhenHighlighted设置为YES。这工作正常,但按钮的“发光”被按钮的父 UIView 剪切。我试过了;

button.layer.masksToBounds = NO;
button.clipsToBounds = NO;
parentView.layer.masksToBounds = NO;
parentView.clipsToBounds = NO;

但这些都不允许发光脱离父视图的边界。这是一个相当小的外观问题,但我认为让这个工作看起来更好

希望有人可以提供帮助!谢谢

it's possible the approach i'm using with this might be a little wrong, and if so perhaps someone can advise... but in any case, a pattern i've got into for creating responder widgets involves adding an invisible UIButtonTypeCustom that fills the bounds of a UIView in order to add backwards-compatible button behaviour to any view. for my needs, this works perfectly well. in order to slightly improve the user experience of using this hybrid button, i set showsTouchWhenHighlighted to YES for the button. this works fine, but the "glow" of the button is clipped by the button's parent UIView. i've tried;

button.layer.masksToBounds = NO;
button.clipsToBounds = NO;
parentView.layer.masksToBounds = NO;
parentView.clipsToBounds = NO;

but none of these allow the glow to escape the bounds of the parentView. it's quite a minor cosmetic issue, but i think it would look nicer to get this working

hope someone can help! thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

听你说爱我 2024-11-08 02:04:54

我使用这样的代码,并且发光不会被父级剪辑 - 经过验证和测试。

UIButton myButton = [[UIButton alloc] init....];
[parentView addSubview:myButton];
myButton.showsTouchWhenHighlighted = YES;
parentView.clipsToBounds = NO;

无需在按钮上设置 .clipsToBounds = NO;默认值已经是NO。

当您设置属性时,您是否检查过 parentView 是否为非零?还要检查层次结构中是否没有另一个可能会剪切发光效果的 UIView

I use code like this, and the glow is not clipped by the parent - verified and tested.

UIButton myButton = [[UIButton alloc] init....];
[parentView addSubview:myButton];
myButton.showsTouchWhenHighlighted = YES;
parentView.clipsToBounds = NO;

No need to set .clipsToBounds = NO on the button; the default is already NO.

Have you checked that parentView is non-nil when you're setting the properties? Check also that there isn't another UIView further up in the hierarchy that might be clipping the glow effect.

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