【问题标题】:How to set a custom pointer effect on a button (Objective-C)?如何在按钮上设置自定义指针效果(Objective-C)?
【发布时间】:2020-07-15 22:48:42
【问题描述】:

如何在按钮上设置自定义指针效果(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 */

【问题讨论】:

    标签: ios objective-c pointers


    【解决方案1】:

    好的,经过反复试验,我想通了!代码如下。

    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;
            };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-28
      • 2020-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-11
      • 1970-01-01
      • 2017-08-25
      相关资源
      最近更新 更多