MNTPullToReact 是 Pull to Refresh 交互的扩展版本。它的主要想法来自一个独特的问题:自然下拉手势是否可以做更多,从而避免占用宝贵内容空间的不美观动作按钮?
您可以绑定任意多的反应到 MNTPullToReact,并让用户通过这种独特且众所周知的手势来访问特定的应用程序操作。
MNTPullToReact 非常容易使用,并且高度可定制。
如果您在您的应用程序中使用 MNTPullToReact,请将您应用程序的链接添加到 应用程序列表。
最后,在演示之前,我想感谢所有的贡献者。如果您忘记了自己的名字,请自行添加到 贡献者列表。总有事要做或改进,因此如果您想寻找特定的贡献方式,可以查看 待办事项列表。
-- Guillaume Sempe,首席移动开发者,mention
MNTPullToReact 是 UIControl
的子类,并采用了在 Apple 的控制中广泛使用的常见 target-action 设计模式。它还模仿了 Apple 的 UIRefreshControl
控制接口,以方便熟悉 Apple Pull to Refresh 控制的开发者使用。
什么是 | UIRefreshControl |
MNTPullToReact |
---|---|---|
感知状态的属性 | BOOL refreshing |
NSInteger action |
启动动作 | beginRefreshing |
beginAction |
结束动作 | endRefreshing |
endAction |
动作所需的 evento | UIControlEventValueChanged |
UIControlEventValueChanged |
这里是一个使用 MNTPullToReactDefaultView 的简短代码示例。以下代码创建了一个具有 4 个动作的 pull to react。
// Import the library header
#import "PullToReact.h"
// In the viewDidLoad create the control
MNTPullToReactControl *reactControl = [[MNTPullToReactControl alloc] initWithNumberOfActions:4];
[reactControl addTarget:self action:@selector(reaction:) forControlEvents:UIControlEventValueChanged];
self.tableView.reactControl = reactControl;
// Than create the target-action method
- (void)reaction:(id)sender
{
// Do the reaction thing
[reactControl endAction:reactControl.action];
}
如果您使用 CocoaPods,请将以下行添加到您的 Podfile
pod 'MNTPullToReact', '~> 1.0'
如果您不使用 CocoaPods,则将所有需要的文件添加到您的项目中,并根据库的 podspec 设置需要的设置。请注意:不要忘记将 -ObjC 添加到其他链接器标志中。
OTHER_LDFLAGS -ObjC
#import "PullToReact.h"
reactControl
属性设置为您想使用的拉取响应。MNTPullToReactControl *reactControl = [[MNTPullToReactControl alloc] initWithNumberOfActions:4];
[reactControl addTarget:_delegateAndDataSource action:@selector(reaction:) forControlEvents:UIControlEventValueChanged];
self.reactControl = reactControl;
#pragma mark - Pull to react target-action method
- (void)reaction:(id)sender
{
MNTPullToReactControl *reactControl = (MNTPullToReactControl *)sender;
NSLog(@"Doing action %ld", (long)reactControl.action);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
usleep(1100 * 1000);
dispatch_async(dispatch_get_main_queue(), ^{
[reactControl endAction:reactControl.action];
});
});
}
一旦您的异步任务已终止,别忘了调用 endAction:
方法来通知 Pull to React 控件。
您可以通过继承 MNTPullToReactView 类来不受限制地自定义自己的 Pull to React 功能。
要了解如何制作令人惊叹的 Pull to React 设计,您可以查看库中提供的 示例。
UIWebView
上有 Pull to React 控件。如果您在应用程序中使用了 MNTPullToReact,请在此处添加您的 App Store 链接。