iPhone开发部分总结_2_
来源:互联网 发布:js判断身份证是否成年 编辑:程序博客网 时间:2024/04/20 02:58
1.将UIColor转换为RGB值
- (void)viewDidLoad{ [superviewDidLoad]; NSMutableArray *mutableArray = [selftheUIColorToRGB:[UIColorredColor]]; //得到红色的RGB数组 NSLog(@"%@",mutableArray);}- (NSMutableArray *)theUIColorToRGB:(UIColor *)color{ NSMutableArray *RGBArray = [[NSMutableArrayalloc]init]; NSString *RGBString = nil; NSString *RGBValue = [NSStringstringWithFormat:@"%@",color]; NSArray *threeArray = [RGBValue componentsSeparatedByString:@" "]; NSLog(@"~~~~%@",RGBValue); NSLog(@"____%@",threeArray); int r = [[threeArray objectAtIndex:1]intValue] *255;//获取红色值 RGBString = [NSStringstringWithFormat:@"%d",r]; [RGBArrayaddObject:RGBString]; int g = [[threeArray objectAtIndex:2]intValue] *255;//获取绿色值 RGBString = [NSStringstringWithFormat:@"%d",g]; [RGBArrayaddObject:RGBString]; int b = [[threeArray objectAtIndex:3]intValue] *255;//获取蓝色值 RGBString = [NSStringstringWithFormat:@"%d",b]; [RGBArrayaddObject:RGBString]; return [RGBArray autorelease];//返回保存RGB的数组}PS:componentsSeparatedByString方法说明:即返回给定分割的数组,例如:NSString *list = @"Norman, Stanley, Fletcher";NSArray *listItems = [list componentsSeparatedByString:@", "];produces an array { @"Norman", @"Stanley", @"Fletcher" }.
2.基本的横竖屏切换实现
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation //允许切换的方向{ if(interfaceOrientation==UIDeviceOrientationPortrait||interfaceOrientation==UIDeviceOrientationPortraitUpsideDown){ //实现代码,通常要改变方向参数、背景图、各控件位置和尺寸、} else{ //手机改变为纵向,做出相应改变 } returnYES;}- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration//方向改变时触发的代理{ if (toInterfaceOrientation ==UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { //竖向,改变同上}elseif (toInterfaceOrientation ==UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation ==UIInterfaceOrientationLandscapeRight) { //横向,改变同上}}
3.显示完UIAlertView后自动消失
无意中发现的好贴,思路很好,可以灵活运用NSTimer实现其它功能,分享学习下。UIAlertView弹出后2s让其自动消失,两种方法:(1)结合NSTimerUIAlertView baseAlert = nil;- (void) performDismiss: (NSTimer *)timer{ [baseAlert dismissWithClickedButtonIndex:0 animated:NO];//important [baseAlert release]; baseAlert = NULL;} - (void) presentSheet{ baseAlert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"\nMessage Message Message " delegate:self cancelButtonTitle:nil otherButtonTitles: nil]; [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector: @selector(performDismiss:) userInfo:nil repeats:NO]; [baseAlert show];}(2)使用PerformSelector:withObject:afterDelay:方法- (void) dimissAlert:(UIAlertView *)alert{ if(alert) { [alert dismissWithClickedButtonIndex:[alert cancelButtonIndex] animated:YES]; [alert release]; }}- (void)showAlert{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; [alert show]; [self performSelector:@selector(dimissAlert:) withObject:alert afterDelay:2.0];}
原址:http://www.cocoachina.com/bbs/read.php?tid=71500&fpage=30
4.横向UITableView的实现
github开源demo:https://github.com/alekseyn/EasyTableView
5.@synchronized的理解
@synchronized(self) 理解为访问互斥
(1)是某个对象实例内,@synchronized(){}可以防止多个线程同时访问这个对象实例的synchronized方法(如果一个对象实例有多个synchronized方法,只要一个线程访问了其中的一个synchronized方法,其它线程不能同时访问这个对象实例中任何一个synchronized方法)。这时,不同的对象实例的synchronized方法是不相干扰的。也就是说,其它线程照样可以同时访问相同类的另一个对象实例中的synchronized方法。
(2)synchronized关键字是不能继承的,也就是说,子类的方法@synchronized (){} 在继承类中并不自动是@synchronized (){},继承类需要显示指定它的某个方法为synchronized方法;
6.存储图片到相册
UIImageWriteToSavedPhotosAlbum(storeImage,self,nil,nil); //存储图片到手机相册API
当遍历某一容器时,不能对该容器的内容进行改动。
8.如何使应用设置到NewsStand(报刊杂志)
在info.plist文件里添加选项:Application presents contents in Newsst Boolean Yes
9.contentsize、contentoffset、contentInset的区别
contentSize是scrollview可以滚动的区域,比如frame = (0 ,0 ,320 ,480) contentSize = (320 ,960),代表你的scrollview可以上下滚动,滚动区域为frame大小的两倍。
contentOffset是scrollview当前显示区域顶点相对于frame顶点的偏移量,比如上个例子你拉到最下面,contentoffset就是(0 ,480),也就是y偏移了480
contentInset是scrollview的contentview的顶点相对于scrollview的位置,例如你的contentInset = (0 ,100),那么你的contentview就是从scrollview的(0 ,100)开始显示
能够理解运用就哦了,下面是个帖子的讨论:
http://www.cocoachina.com/bbs/read.php?tid=38430
10.UIEdgeInsetsMake用法
查找API得到:
UIEdgeInsets UIEdgeInsetsMake(CGFloat top,CGFloat left,CGFloat bottom,CGFloat right) {
UIEdgeInsets insets = {top, left, bottom, right};
return insets;
}
PS:和 frame的设置不同,设置的4个参数是从顶点逆时针开始。- iPhone开发部分总结_2_
- iPhone开发部分总结
- iPhone开发部分总结
- iPhone开发部分总结_1_
- iPhone开发部分总结_3_
- iPhone开发部分总结(1)
- iPhone开发部分总结_3_
- 汇编总结-第二部分_2_数据处理
- 部分iPhone开发题目
- [iphone开发私房菜_2_] 为UIToolBar工具条添加各种各样的UIBbarButtonItem
- [iphone开发私房菜_2_] 为UIToolBar工具条添加各种各样的UIBbarButtonItem
- Redis学习总结_2_对象
- iphone开发总结1
- iPhone 开发阶段性总结
- iPhone开发阶段性总结
- 初学iphone开发总结
- iPhone开发经验教训总结
- iphone开发面试总结
- 通过rsync+inotify实现数据的实时备份
- java,取网络图片并缩小
- 用eclipse开发安卓(安装)
- 堆和栈的区别 (转贴)
- 健康-------------医学小常识
- iPhone开发部分总结_2_
- Vim简明教程
- 黑马程序员--File类的笔记(一)
- [转] 程序员面试、算法研究、编程艺术、红黑树4大系列集锦与总结
- 推荐 书目《Ruby on Rails 實戰聖經 ---使用 Rails 3.2 及 Ruby 1.9.3》
- 第6题 约瑟夫环问题
- 全面的framebuffer详解
- linux安装php扩展json
- 利用SecureCRT在linux与Windows之间传输文件