iOS 开发技巧收集整理
2015-11-28 11:36
459 查看
1.使用NSTimer和CGAffineTransform实现最简单的旋转动画
2.给UILabel添加背景图片
3.UIWebView加载播放Gif图,可用作引导图
4.导航栏按钮,最左或最右会有10个像素点左右是非响应区域,解决方法
5.监听程序进入后台,前台
6.跳转到苹果商店
7.给Label加删除线
8.本页面隐藏导航栏PUSH到下一页面,POP回来时导航栏出现黑色底部问题,解决方案
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
CGAffineTransform transform=CGAffineTransformMakeRotation(angle); view.transform = transform;注:angle是浮点型参数,代表角度,表示距离原角度旋转了多少
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. _angle = 0; UIImageView* animationImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image"]]; animationImage.frame=CGRectMake(100, 200, 100, 100); [self.view addSubview:animationImage]; //初始化定时器NSTimer [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(startTimer:) userInfo:animationImage repeats:YES]; } - (void)startTimer:(NSTimer *)tiemr { UIImageView *animationImage = timer.userInfo; _angle = _angle + 0.05;//angle角度 double angle; if (_angle > 6.28) {//大于 M_PI*2(360度) 角度再次从0开始 _angle = 0; } CGAffineTransform transform=CGAffineTransformMakeRotation(_angle); animationImage.transform = transform; }
2.给UILabel添加背景图片
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 300, 200)]; label.text = @"背景图片如我"; label.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"image"]]; [self.view addSubview:label];
3.UIWebView加载播放Gif图,可用作引导图
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"1111" ofType:@"gif"]; NSData *gif = [NSData dataWithContentsOfFile:filePath]; UIWebView *web = [[UIWebView alloc] initWithFrame:self.view.frame]; [web loadData:gif MIMEType:@"image/gif" textEncodingName:nil baseURL:nil]; web.userInteractionEnabled = NO; [self.view addSubview:web];
4.导航栏按钮,最左或最右会有10个像素点左右是非响应区域,解决方法
UIButton *leftButton= [UIButton buttonWithType:UIButtonTypeCustom]; leftButton.frame = CGRectMake(0, 0, 24, 20); UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton]; UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; negativeSpacer.width = -10; self.navigationItem.leftBarButtonItems = @[negativeSpacer,leftItem];
5.监听程序进入后台,前台
-(void)initNotification{ //监听是否重新进入程序程序. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(whenAppBecomActive) name:UIApplicationDidBecomeActiveNotification object:nil]; //监听是否触发home键挂起程序. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(whenAppResignActive) name:UIApplicationWillResignActiveNotification object:nil]; } -(void)whenAppBecomActive{ NSLog(@"重新进入程序"); } -(void)whenAppResignActive{ NSLog(@"home键挂起程序,进入后台"); }
6.跳转到苹果商店
NSString *UrlString = [NSString stringWithFormat:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=1004900105" ]; if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0)){ UrlString = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id1004900105"]; } [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UrlString]];
7.给Label加删除线
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 30)]; NSString *oldString = @"aaaaaaaaaaa"; NSMutableAttributedString *attributString = [[NSMutableAttributedString alloc] initWithString:oldString]; [attributString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, 11)]; label.attributedText = attributString; label.textColor = [UIColor grayColor]; [self.view addSubview:label];
8.本页面隐藏导航栏PUSH到下一页面,POP回来时导航栏出现黑色底部问题,解决方案
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- 绝大部分 Android 手电筒应用需要大量权限
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 这些看似合法的 iPhone Lightning 数据线将劫持您的电脑
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 我的iPhone桌面
- 三种检测iPhone/iPad设备方向的方法
- js实现iPhone界面风格的单选框和复选框按钮实例
- 分享经典的JavaScript开发技巧
- PHP技术开发技巧分享
- PHP开发中常用的8个小技巧
- jQuery常见开发技巧详细整理
- 讲解iOS开发中基本的定位功能实现