iOS11 DragAndDrop适配之UISpringLoadedInteraction

这是iOS11 Drag&Drop适配的一系列文章

我们可以在iOS的human-interface-guideline里面看到,drag&drop下提到了要尽量去适配UISpringLoadedInteraction。什么是UISpringLoadedInteraction呢,最好的例子就是UINavigationBarItem,iOS11原生的UINavigationBarItem就已经适配了UISpringLoadedInteraction。当我们将一个Drag操作移动到UINavigationBarItem的时候,我们可以看到这个item被选中,过了一会开始闪烁,并进行对应的操作。这个效果就是配置了UISpringLoadedInteraction。更多的运用,可以参考原生的备忘录。

从guideline我们可以看到,如果我们进行Drag&Drop适配的时候,一般情况下都会需要进行页面跳转,这时候我们需要对不同View添加UISpringLoadedInteraction进行操作。

简单的代码如下:


UISpringLoadedInteraction *springInteraction = [[UISpringLoadedInteraction alloc] initWithActivationHandler:^(UISpringLoadedInteraction * _Nonnull interaction, id  _Nonnull context) {
            HandleViewActivationBlock block = [weakSelf getHandleViewActivationBlock];
// Do something here
        }];

[self addInteraction:springInteraction];

因为需要对大量的View,Cell以及按钮进行配置,需要写大量的重复代码,在这里我写了一个UIView的Category,只要两个方法就可以就View进行UISpringLoadedInteraction的适配。

Demo预览:


iOS11 DragAndDrop适配之UISpringLoadedInteraction_第1张图片
WechatIMG318.jpeg

地址:
https://github.com/kingandyoga/UserfulUISpringLoadedInteraction

你可能感兴趣的:(iOS11 DragAndDrop适配之UISpringLoadedInteraction)