[英]How to set a custom pointer effect on a button (Objective-C)?
如何在按钮上设置自定义指针效果(Objective-C)?
backToProjectsButton.pointerInteractionEnabled = YES;
UITargetedPreview *preview = [[UITargetedPreview alloc] initWithView:backToProjectsButton];
UIPointerStyle *buttonPointerStyle = [UIPointerStyle styleWithEffect:[UIPointerHighlightEffect effectWithPreview:preview] shape:[UIPointerShape shapeWithRoundedRect:backToProjectsButton.bounds]];
backToProjectsButton.pointerStyleProvider = /* NOT SURE WHAT COMES NEXT */
好的,经过反复试验,我想通了。 代码如下。
backToProjectsButton.pointerStyleProvider = ^UIPointerStyle*(UIButton *button, UIPointerEffect *proposedEffect, UIPointerShape *proposedShape){
CGRect buttonRect = CGRectInset(button.bounds, -12, -14);
buttonRect = [button convertRect:buttonRect toView:proposedEffect.preview.target.container];
UIPointerStyle *buttonPointerStyle = [UIPointerStyle styleWithEffect:[UIPointerHighlightEffect effectWithPreview:proposedEffect.preview] shape:[UIPointerShape shapeWithRoundedRect:buttonRect]];
return buttonPointerStyle;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.