UIView 内的 UIButton,带有showTouchWhenHighlighted 辉光被超级视图剪裁
我使用的方法可能有点错误,如果是这样,也许有人可以建议......但无论如何,我用于创建响应程序小部件的模式涉及添加一个不可见的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用这样的代码,并且发光不会被父级剪辑 - 经过验证和测试。
无需在按钮上设置 .clipsToBounds = NO;默认值已经是NO。
当您设置属性时,您是否检查过
parentView
是否为非零?还要检查层次结构中是否没有另一个可能会剪切发光效果的UIView
。I use code like this, and the glow is not clipped by the parent - verified and tested.
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 anotherUIView
further up in the hierarchy that might be clipping the glow effect.