iOS手势用法总结新手入门指南

iOS 手势的各种姿势,新手一开始确实容易搞混,尤其是像UIPanGestureRecognizerUISwipeGestureRecognizer这种听起来都能拖,实际用法却差挺多的。这篇资源总结得比较全,不光讲原理,还搭配了例子和演示项目,蛮适合拿来练手。

轻扫手势里头,UISwipeGestureRecognizer适合做切换页面那种一滑就触发的操作;UIPanGestureRecognizer更灵活,像拖动视图、实现自定义滑动手势啥的都能派上用场。

点击手势用得最多,大到图片预览、按钮交互,小到表格里的轻点都少不了UITapGestureRecognizer。支持单双击分开,还挺方便的。

捏合、旋转这些手势一般配合图片、地图使用,比如放大照片、旋转模型,用UIPinchGestureRecognizerUIRotationGestureRecognizer都能搞定,响应也快。

UIScreenEdgePanGestureRecognizer这种边缘滑动,在导航返回时有用。还记得微信那种左滑返回的手感吧?就是靠它。

另外,iOS 11 之后加入的UIDragInteractionUIDropInteraction也还不错,可以实现拖拽文本或图片到其他视图,做点文件管理类的功能也方便。

手势冲突也是个重点,比如你页面上同时有点击和长按,容易抢手势。可以通过requireGestureRecognizerToFail:这类方式手动调整优先级,避免手势打架。

资源里附带的UIGestureDemo项目比较直观,点进去就能看到各种手势的交互效果,拿来当模板也行。代码结构清晰,适合新手照着写一遍。

如果你刚开始学 iOS,搞不清各类手势的差别和用法,这篇挺值得一看;顺便多试试组合手势的写法,对提升交互体验蛮有的。

zip
UIGestureDemo.zip 预估大小:45个文件
folder
UIGestureDemo 文件夹
file
UIShakeAnimation.m 1KB
folder
UIGestureDemo 文件夹
file
UIPanViewController.h 242B
file
main.m 344B
file
UIPanViewController.m 1KB
file
BaseViewController.m 1KB
file
UISwipeViewController.m 2KB
file
UITapViewController.h 242B
file
AppDelegate.h 287B
file
AppDelegate.m 2KB
folder
Base.lproj 文件夹
file
LaunchScreen.xib 4KB
file
RootViewController.h 231B
file
.DS_Store 6KB
file
UITouchViewController.m 2KB
file
UITouchViewController.h 246B
file
UIPinchViewController.m 2KB
file
UITapViewController.m 2KB
file
UIPinchViewController.h 246B
file
UIRotationViewController.h 252B
file
BaseViewController.h 307B
file
UISwipeViewController.h 246B
folder
Images.xcassets 文件夹
folder
AppIcon.appiconset 文件夹
file
Contents.json 585B
file
.DS_Store 6KB
file
Info.plist 1KB
file
RootViewController.m 2KB
file
UILongPressViewController.m 2KB
file
UIRotationViewController.m 2KB
file
UILongPressViewController.h 254B
folder
UIGestureDemoTests 文件夹
file
Info.plist 758B
file
UIGestureDemoTests.m 887B
file
Day9.rtf 5KB
folder
UIGestureDemo.xcodeproj 文件夹
folder
project.xcworkspace 文件夹
file
contents.xcworkspacedata 158B
folder
xcuserdata 文件夹
folder
brooksong.xcuserdatad 文件夹
file
UserInterfaceState.xcuserstate 22KB
folder
sxxb.xcuserdatad 文件夹
file
UserInterfaceState.xcuserstate 13KB
file
UserInterfaceState_20160608152022.xcuserstate 12KB
folder
qianfeng.xcuserdatad 文件夹
file
UserInterfaceState.xcuserstate 14KB
file
project.pbxproj 22KB
folder
xcuserdata 文件夹
folder
brooksong.xcuserdatad 文件夹
folder
xcschemes 文件夹
file
xcschememanagement.plist 575B
file
UIGestureDemo.xcscheme 4KB
folder
sxxb.xcuserdatad 文件夹
folder
xcschemes 文件夹
file
xcschememanagement.plist 575B
file
UIGestureDemo.xcscheme 4KB
folder
qianfeng.xcuserdatad 文件夹
folder
xcschemes 文件夹
file
xcschememanagement.plist 575B
file
UIGestureDemo.xcscheme 4KB
file
.DS_Store 6KB
file
img.jpg 100KB
file
UIShakeAnimation.h 389B
zip 文件大小:164.75KB