- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章ios仿侧边抽屉效果实现代码由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
效果图如下 。
代码实现以及思路下面分析: 代码创建导航控制器 appdelegate.m中 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#import "appdelegate.h"
#import "viewcontroller.h"
@interface appdelegate ()
@end
@implementation appdelegate
- (
bool
)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {
self.window = [[uiwindow alloc] initwithframe:[uiscreen mainscreen].bounds];
viewcontroller * vc = [[viewcontroller alloc] init];
//必须要初始化导航控制器的根控制器
uinavigationcontroller * nav = [[uinavigationcontroller alloc] initwithrootviewcontroller:vc];
self.window.rootviewcontroller = nav;
[self.window makekeyandvisible];
return
yes;
}
|
viewcontroller.m中 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
//
// viewcontroller.m
// pbsliedmenu
//
// created by 裴波波 on 16/4/21.
// copyright © 2016年 裴波波. all rights reserved.
//
#import "viewcontroller.h"
#define kscreenh [uiscreen mainscreen].bounds.size.height
#define kscreenw [uiscreen mainscreen].bounds.size.width
#define knavw 64
@interface viewcontroller ()<uitableviewdelegate,uitableviewdatasource>
@property (nonatomic, strong) uitableview *tableview;
/** 记录是否打开侧边栏 */
@property (nonatomic, assign)
bool
openslide;
/** 侧栏按钮 */
@property (nonatomic, strong) uibarbuttonitem *btnleft;
@end
|
用一个bool值来记录左侧view是打开还是关闭状态.每次点击都要改变记录tableview状态的值 用属性保存 侧栏 按钮,用来当左侧tableview正在弹出或者收回执行动画过程中禁用. 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
@implementation viewcontroller
#pragma mark - 选中某个cell代理方法
-(
void
)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath{
uitableviewcell * cell = [tableview cellforrowatindexpath:indexpath];
nslog(@
"%@"
,cell.textlabel.text);
//选中cell后立即取消选中
[tableview deselectrowatindexpath:indexpath animated:yes];
}
#pragma mark - tableview数据源
-(nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section{
return
20;
}
-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{
static
nsstring * id = @
"cell"
;
uitableviewcell * cell = [tableview dequeuereusablecellwithidentifier:id forindexpath:indexpath];
cell.textlabel.text = [nsstring stringwithformat:@
"我是%zd"
,indexpath.row];
cell.backgroundcolor = [uicolor orangecolor];
return
cell;
}
- (
void
)viewdidload {
[super viewdidload];
self.view.backgroundcolor = [uicolor whitecolor];
[self initleftbarbutton];
//注册cell
[self.tableview registerclass:[uitableviewcell
class
] forcellreuseidentifier:@
"cell"
];
}
|
注意:注册cell的同时调用了 self.tableview 则调用了懒加载,此时tableview已经创建了.必须要先创建,否则有一个小bug就是,当tableview第一次弹出的时候会从屏幕的(0,0)点弹出,而不是整个tableview从左侧弹出. 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#pragma mark - 初始化侧栏按钮
-(
void
)initleftbarbutton{
uibutton * btnleft = [[uibutton alloc] init];
btnleft.frame = cgrectmake(0, 0, 90, 40);
[btnleft settitle:@
"侧栏"
forstate:uicontrolstatenormal];
[btnleft settitlecolor:[uicolor blackcolor] forstate:uicontrolstatenormal];
[btnleft addtarget:self action:@selector(didleftbtn) forcontrolevents:uicontroleventtouchupinside];
self.navigationitem.leftbarbuttonitem = [[uibarbuttonitem alloc] initwithcustomview:btnleft];
self.btnleft = self.navigationitem.leftbarbuttonitem;
}
#pragma mark - 懒加载tableview
-(uitableview *)tableview{
if
(_tableview == nil) {
_tableview = [[uitableview alloc] init];
_tableview.delegate = self;
_tableview.datasource = self;
_tableview.backgroundcolor = [uicolor orangecolor];
//第一次点击tableview从左上角弹出,优化方案--先创建出tableview
cgfloat hight = kscreenh;
cgfloat x = 0;
cgfloat y = knavw;
cgfloat width = 0;
_tableview.frame = cgrectmake(x, y, width, hight);
//取消显示竖直滚动条
_tableview.showsverticalscrollindicator = no;
}
return
_tableview;
}
|
懒加载的时候直接创建tableview,让其宽度 == 0 即可. 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#pragma mark - 点击侧栏按钮弹出tableview
-(
void
)didleftbtn{
//禁用button等待动画执行完毕再启用button
self.btnleft.enabled = no;
cgfloat hight = kscreenh;
cgfloat x = 0;
cgfloat y = knavw;
if
(!self.openslide) {
//添加动画
[uiview animatewithduration:0.3 animations:^{
cgfloat width = kscreenw / 3;
self.tableview.frame = cgrectmake(x, y, width, hight);
}];
[self.view addsubview:self.tableview];
}
else
{
[uiview animatewithduration:0.3 animations:^{
cgfloat width = 0;
self.tableview.frame = cgrectmake(x, y, width, hight);
}];
}
//执行完毕动画 取消禁用button
[self performselector:@selector(setbtnleftenabled) withobject:nil afterdelay:0.3];
//监视侧栏是否打开
if
(self.openslide == yes) {
self.openslide = no;
}
else
{
self.openslide = yes;
}
}
|
点击 侧栏 按钮弹出tableview,此过程中让其动画执行,不会显得生硬.让tableview的宽度从0---> 屏幕宽度的三分之一 记录tableview打开的状态. 执行动画的过程中禁用 侧栏 按钮,由于代码执行时间的瞬间完成的,动画执行时间是0.3s,则延迟0.3s取消禁用 侧栏 按钮. 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
//不用反复创建tableview
//#pragma mark - 移除tableview
//-(void)removesliedview{
//
// [self.tableview removefromsuperview];
// self.btnleft.enabled = yes;
//}
#pragma mark - 动画执行完毕启用"侧栏"按钮
-(
void
)setbtnleftenabled{
self.btnleft.enabled = yes;
//动画执行完毕让第一个cell显示在最顶端
self.tableview.contentoffset = cgpointmake(0, 0);
}
- (
void
)didreceivememorywarning {
[super didreceivememorywarning];
// dispose of any resources that can be recreated.
}
@end
|
之前犯过一个错误就是点击 侧栏 按钮创建tableview,再点击 销毁 tableview,这样比较耗性能.通过懒加载先创建tableview,收回tableview的时候让其宽度 == 0 即可. 上图演示的可以看出,当滑动tableview的时候,再次点击进去tableview还是滑动的位置,不会恢复到开始 下标为 0 的cell为最上面显示的cell.优化方案:让tableview的偏移contentoffset等于 0即可.代码不能写在 弹出tableview 与 收回 tableview的动画代码中,因为这样会让人看出来.写在动画执行完毕后的代码中. 。
源代码地址:https://git.oschina.net/alexpei/pbsliedmenu.git 。
以上就是本文的全部内容,希望对大家的学习有所帮助.
最后此篇关于ios仿侧边抽屉效果实现代码的文章就讲到这里了,如果你想了解更多关于ios仿侧边抽屉效果实现代码的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
IO 设备如何知道属于它的内存中的值在memory mapped IO 中发生了变化? ? 例如,假设内存地址 0 专用于保存 VGA 设备的背景颜色。当我们更改 memory[0] 中的值时,VGA
我目前正在开发一个使用Facebook sdk登录(通过FBLoginView)的iOS应用。 一切正常,除了那些拥有较旧版本的facebook的人。 当他们按下“使用Facebook登录”按钮时,他
假设我有: this - is an - example - with some - dashesNSRange将使用`rangeOfString:@“-”拾取“-”的第一个实例,但是如果我只想要最后
Card.io SDK提供以下详细信息: 卡号,有效期,月份,年份,CVV和邮政编码。 如何从此SDK获取国家名称。 - (void)userDidProvideCreditCardInfo:(Car
iOS 应用程序如何从网络服务下载图片并在安装过程中将它们安装到用户的 iOS 设备上?可能吗? 最佳答案 您无法控制应用在用户设备上的安装,因此无法在安装过程中下载其他数据。 只需在安装后首次启动应
我曾经开发过一款企业版 iOS 产品,我们公司曾将其出售给大型企业,供他们的员工使用。 该应用程序通过 AppStore 提供,企业用户获得了公司特定的配置文件(包含应用程序配置文件)以启用他们有权使
我正在尝试将 Card.io SDK 集成到我的 iOS 应用程序中。我想为 CardIO ui 做一个简单的本地化,如更改取消按钮标题或“在此保留信用卡”提示文本。 我在 github 上找到了这个
我正在使用 CardIOView 和 CardIOViewDelegate 类,没有可以设置为 YES 的 BOOL 来扫描 collectCardholderName。我可以看到它在 CardIOP
我有一个集成了通话工具包的 voip 应用程序。每次我从我的 voip 应用程序调用时,都会在 native 电话应用程序中创建一个新的最近通话记录。我在 voip 应用程序中也有自定义联系人(电话应
iOS 应用程序如何知道应用程序打开时屏幕上是否已经有键盘?应用程序运行后,它可以接收键盘显示/隐藏通知。但是,如果应用程序在分屏模式下作为辅助应用程序打开,而主应用程序已经显示键盘,则辅助应用程序不
我在模拟器中收到以下错误: ImageIO: CGImageReadSessionGetCachedImageBlockData *** CGImageReadSessionGetCachedIm
如 Apple 文档所示,可以通过 EAAccessory Framework 与经过认证的配件(由 Apple 认证)进行通信。但是我有点困惑,因为一些帖子告诉我它也可以通过 CoreBluetoo
尽管现在的调试器已经很不错了,但有时找出应用程序中正在发生的事情的最好方法仍然是古老的 NSLog。当您连接到计算机时,这样做很容易; Xcode 会帮助弹出日志查看器面板,然后就可以了。当您不在办公
在我的 iOS 应用程序中,我定义了一些兴趣点。其中一些有一个 Kontakt.io 信标的名称,它绑定(bind)到一个特定的 PoI(我的意思是通常贴在信标标签上的名称)。现在我想在附近发现信标,
我正在为警报提示创建一个 trigger.io 插件。尝试从警报提示返回数据。这是我的代码: // Prompt + (void)show_prompt:(ForgeTask*)task{
您好,我是 Apple iOS 的新手。我阅读并搜索了很多关于推送通知的文章,但我没有发现任何关于 APNS 从 io4 到 ios 6 的新更新的信息。任何人都可以向我提供 APNS 如何在 ios
UITabBar 的高度似乎在 iOS 7 和 8/9/10/11 之间发生了变化。我发布这个问题是为了让其他人轻松找到答案。 那么:在 iPhone 和 iPad 上的 iOS 8/9/10/11
我想我可以针对不同的 iOS 版本使用不同的 Storyboard。 由于 UI 的差异,我将创建下一个 Storyboard: Main_iPhone.storyboard Main_iPad.st
我正在写一些东西,我将使用设备的 iTunes 库中的一部分音轨来覆盖 2 个视频的组合,例如: AVMutableComposition* mixComposition = [[AVMutableC
我创建了一个简单的 iOS 程序,可以顺利编译并在 iPad 模拟器上运行良好。当我告诉 XCode 4 使用我连接的 iPad 设备时,无法编译相同的程序。问题似乎是当我尝试使用附加的 iPad 时
我是一名优秀的程序员,十分优秀!