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);

被折叠的 条评论
为什么被折叠?



