iOS开发的一些小方法

1.设置自定义代码块到code snippets:

我常用#pragma mark - 来将代码进行分块,使代码看起来更整洁,先在代码区输入#pragma mark - <#name#>,然后全选拖入code snippets,设置相关信息即完成。



2.长按3秒实现事件:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    _mdt = event.timestamp;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    if(event.timestamp - _mdt > 3){
                // do somthing
}


3.连续dismiss两个Controller:

[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];


4.双击UIButton:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(100, 100, 100, 40);
button.backgroundColor = [UIColor redColor];
[button addTarget:self action:@selector(tabButtion:forEvent:) forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(repeatButtion:forEvent:) forControlEvents:UIControlEventTouchDownRepeat];
[self.view addSubview:button];
- (void)tabButtion:(UIButton *)sender forEvent:(UIEvent *)event
{
    [self performSelector:@selector(ClickTap:) withObject:sender afterDelay:0.2];
}

- (void)ClickTap:(UIButton *)sender
{
    NSLog(@"单击操作");
}

- (void)repeatButtion:(UIButton *)sender forEvent:(UIEvent *)event
{
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(ClickTap:) object:sender];
    NSLog(@"双击操作");
}

5.摇一摇:

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    NSLog(@"摇一摇。。。。。。");
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
   NSLog(@"motionEnded");
}

- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
   NSLog(@"motionCancelled");
}

6.获取APP的相关信息:

//app版本号(Bundle versions string, short(info) ------ version(general))
NSString *app_Version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
//app build版本(Bundle version(info) ------ build(general))
NSString *app_Build = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
//获取项目名称(Bundle name)
NSString *excuttable = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey];
//获取项目版本号
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];
//app名称(Bundle display name)
NSString *app_Name = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];

7.scale和bounds:

//相对于屏幕尺寸的比例
CGFloat count = [[UIScreen mainScreen] scale];
//屏幕分辨率
CGRect rect = [[UIScreen mainScreen] bounds];
//app状态栏尺寸
CGRect static_rect = [[UIApplication sharedApplication] statusBarFrame];
//屏幕尺寸,去掉状态栏
CGRect frame = [[UIScreen mainScreen] applicationFrame];


8.程序休眠、直接退出程序:

//休眠两秒
[NSThread sleepForTimeInterval:.2f];
//直接退出程序
exit(0);







评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值