iOS自定义下拉菜单示例

iOS 的下拉菜单交互,用原生的方式做,其实没那么复杂。这份 Demo 就是个挺好上手的例子,逻辑清晰、动效自然,用来参考或者直接集成都比较方便。整个展开逻辑也就几行代码,frame高度一拉,bringSubviewToFront搞定遮挡问题,动画也走的是老牌的beginAnimations套路,嗯,响应也快,不卡顿。

适合那种界面空间比较紧凑,但又想搞个原生风格的选择列表场景,比如设置页、筛选项啥的。你要做的事就一件——判断showList,决定是展开还是不动。

如果你想深入折腾,可以再搭配下UIView 的阴影效果,下拉菜单看起来更立体,不那么单薄。或者想换个方向,参考下jQuery 版的下拉菜单插件,Web 上用的更多,样式也多。

小提醒:原始代码里用的是UIView.beginAnimations,虽然还挺稳,但如果你项目是 iOS 10+,建议考虑换成UIViewPropertyAnimator,更现代、扩展性也强。

,这份 Demo 适合当做参考,是你想快速搞出个能用的原生下拉菜单,不用第三方库那种。

zip
listDemo.zip 预估大小:20个文件
folder
listDemo 文件夹
folder
listDemo 文件夹
file
ListViewController.h 225B
file
main.m 338B
file
listDemo-Info.plist 1KB
file
Default.png 6KB
file
DropListView.m 4KB
file
AppDelegate.h 279B
file
AppDelegate.m 2KB
file
Default-568h@2x.png 18KB
file
.DS_Store 6KB
file
ListViewController.m 1KB
file
listDemo-Prefix.pch 319B
file
Default@2x.png 16KB
file
DropListView.h 689B
folder
en.lproj 文件夹
file
InfoPlist.strings 45B
folder
listDemo.xcodeproj 文件夹
folder
project.xcworkspace 文件夹
file
contents.xcworkspacedata 153B
folder
xcuserdata 文件夹
folder
Eminem.xcuserdatad 文件夹
file
UserInterfaceState.xcuserstate 15KB
file
project.pbxproj 13KB
folder
xcuserdata 文件夹
folder
Eminem.xcuserdatad 文件夹
folder
xcschemes 文件夹
file
listDemo.xcscheme 3KB
file
xcschememanagement.plist 480B
file
.DS_Store 12KB
zip 文件大小:35.23KB