[英]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.