ios 技巧点
来源:互联网 发布:mysql字段拼接 编辑:程序博客网 时间:2024/05/30 23:39
1.手势
[A requireGestureRecognizerToFail:B]函数,它可以指定当A手势发生时,即便A已经滿足条件了,也不会立刻触发,会等到指定的手势B确定失败之后才触发
2. UISCrollView 添加swipe手势
1.给手势识别器设置代理, 2.实现代理的方法,都返回为yes
3. 在导航上方设置个提示框
localNavigationController.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d", badgeCount];
导航标题的设置: self.navigationBar.topItem.title = @"Synchronous Requests";
4. 自定义 导航推出界面 的动画
- (void) showLoginView{ [mNavigationController setNavigationBarHidden:NO animated:NO]; CATransition *animation = [CATransition animation]; [animation setDuration:0.5f]; [animation setType: kCATransitionPush]; [animation setSubtype: kCATransitionFromTop]; animation.timingFunction = UIViewAnimationCurveEaseInOut; LoginViewController *loginController = [[LoginViewController alloc] init]; [mNavigationController pushViewController:loginController animated:NO]; [mNavigationController.view.layer addAnimation:animation forKey:nil]; [mainWindow insertSubview:mNavigationController.view atIndex:0];}
1 随机数的使用
头文件的引用
#import <time.h>
#import <mach/mach_time.h>
srandom()的使用
srandom((unsigned)(mach_absolute_time() & 0xFFFFFFFF));
直接使用 random() 来调用随机数2 在UIImageView 中旋转图像
float rotateAngle = M_PI;
CGAffineTransform transform =CGAffineTransformMakeRotation(rotateAngle);
imageView.transform = transform;
以上代码旋转imageView, 角度为rotateAngle, 方向可以自己测试哦!3 在Quartz中如何设置旋转点
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg.png"]];
imageView.layer.anchorPoint = CGPointMake(0.5, 1.0);
这个是把旋转点设置为底部中间。记住是在QuartzCore.framework中才得到支持。4 创建.plist文件并存储
NSString *errorDesc; //用来存放错误信息
NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:4]; //NSDictionary, NSData等文件可以直接转化为plist文件
NSDictionary *innerDict;
NSString *name;
Player *player;
NSInteger saveIndex;
for(int i = 0; i < [playerArray count]; i++) {
player = nil;
player = [playerArray objectAtIndex:i];
if(player == nil)
break;
name = player.playerName;// This "Player1" denotes the player name could also be the computer name
innerDict = [self getAllNodeInfoToDictionary:player];
[rootObj setObject:innerDict forKey:name]; // This "Player1" denotes the person who start this game
}
player = nil;
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:(id)rootObj format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc];
红色部分可以忽略,只是给rootObj添加一点内容。这个plistData为创建好的plist文件,用其writeToFile方法就可以写成文件。下面是代码:
/*得到移动设备上的文件存放位置*/
NSString *documentsPath = [self getDocumentsDirectory];
NSString *savePath = [documentsPath stringByAppendingPathComponent:@"save.plist"];
/*存文件*/
if (plistData) {
[plistData writeToFile:savePath atomically:YES];
}
else {
NSLog(errorDesc);
[errorDesc release];
}
- (NSString *)getDocumentsDirectory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [paths objectAtIndex:0];
}4 读取plist文件并转化为NSDictionary
NSString *documentsPath = [self getDocumentsDirectory];
NSString *fullPath = [documentsPath stringByAppendingPathComponent:@"save.plist"];
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:fullPath];5 读取一般性文档文件
NSString *tmp;
NSArray *lines; /*将文件转化为一行一行的*/
lines = [[NSString stringWithContentsOfFile:@"testFileReadLines.txt"]
componentsSeparatedByString:@"\n"];
NSEnumerator *nse = [lines objectEnumerator];
// 读取<>里的内容
while(tmp = [nse nextObject]) {
NSString *stringBetweenBrackets = nil;
NSScanner *scanner = [NSScanner scannerWithString:tmp];
[scanner scanUpToString:@"<" intoString:nil];
[scanner scanString:@"<" intoString:nil];
[scanner scanUpToString:@">" intoString:&stringBetweenBrackets];
NSLog([stringBetweenBrackets description]);
}
对于读写文件,还有补充,暂时到此。随机数和文件读写在游戏开发中经常用到。所以把部分内容放在这,以便和大家分享,也当记录,便于查找。6 隐藏NavigationBar
[self.navigationController setNavigationBarHidden:YES animated:YES];
在想隐藏的ViewController中使用就可以了。7. 设置cell的点击效果
UIImageview * imgv = ;cell.selectedBackgroundView = imgv;didselected: 中加入[tableView deselectRowAtIndexPath:indexPath animated:YES]; //实现动画效果8 导航的常见设置
[UINavigationBar appearance] setBackgroundImage: ]; //导航背景[UINavigationBar appearance] setTitleTextAttritudes: ]; // 导航字体[UIBarButtonItem appearance] setBackgroundImage: ] ; // 导航按钮背景[UIBarButtonItem appearance] setBackButtonBackgoundImage: ]; // 导航返回按钮背景[UITabBar appearance] setBackgroundImage: ]; // TabBar 背景[UITabBar appearance] setSelectionIndicatorImage:];// TabBar 选中图标9.slider滑轮左右侧图片,滚轮本身图片
[UISlider appearance] setMaximumtrackImage: ];[UISlider appearance] setMinimumtrackImage: ];[UISlider appearance] ]setThumbImage: ] ;10: UISegment背景,间隔部分图片
[UISegmentedControl appearance]setBackgroundImage];[UISegmentedControl appearance]setDividerImage];11:UISwitch打开的时候的背景颜色
[UISwitch appearance] setOnTintColor:];
- ios 技巧点
- 几点iOS开发技巧
- 几点iOS开发技巧
- 几点 iOS 开发技巧
- 几点iOS开发技巧
- 几点 iOS 开发技巧
- 几点iOS开发技巧
- 几点iOS开发技巧
- iOS几点开发技巧
- [译] 几点 iOS 开发技巧
- [译] 几点 iOS 开发技巧
- ios中常用小技巧注意点
- iOS开发技巧--点属性的小隐晦技巧
- iOS 小技巧及注意点(OC)
- iOS 【UIKit-设置navigationBar统一样式几点技巧】
- iOS 技巧
- ios技巧
- iOS技巧
- 音视频编解码学习1
- Spring-ldap 操作LDAP
- 一个无聊的小程序,随机尾数出现的概率
- YUV420、YUV422、RGB24转换
- 3 文件压缩
- ios 技巧点
- 开源日志系统比较
- 追高
- 在iPhone应用里直接打开app store评论页面的方法
- 用powerDesigner设计CDM的时候Association按钮不亮
- 全峰快递30%股权被国美收购!
- 单例模式
- RGB 24和YUY2相互转换
- HTTP协议的头信息详解