1:统一修改导航栏的样式,在 AppDelegate.m中

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  2. {
  3. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  4. // Override point for customization after application launch.
  5. self.window.backgroundColor = [UIColor whiteColor];
  6.  
  7. //设置导航条样式
  8. [self customizeInterface];
  9.  
  10. if ([Login isLogin]) {
  11. [self setupTabViewController];
  12. }else{
  13. [UIApplication sharedApplication].applicationIconBadgeNumber = ;
  14. [self setupLoginViewController];
  15. }
  16. [self.window makeKeyAndVisible];
  17. return YES;
  18. }
  19.  
  20. - (void)customizeInterface {
  21. //设置Nav的背景色和title色
  22. UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
  23. NSDictionary *textAttributes = nil;
  24. if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
  25. [navigationBarAppearance setTintColor:[UIColor whiteColor]];//返回按钮的箭头颜色
  26. [[UITextField appearance] setTintColor:[UIColor colorWithHexString:@"0x3bbc79"]];//设置UITextField的光标颜色
  27. [[UITextView appearance] setTintColor:[UIColor colorWithHexString:@"0x3bbc79"]];//设置UITextView的光标颜色
  28. [[UISearchBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"0xe5e5e5"]] forBarPosition: barMetrics:UIBarMetricsDefault];
  29.  
  30. textAttributes = @{
  31. NSFontAttributeName: [UIFont boldSystemFontOfSize:kNavTitleFontSize],
  32. NSForegroundColorAttributeName: [UIColor whiteColor],
  33. };
  34. } else {
  35. #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
  36. [[UISearchBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"0xe5e5e5"]]];
  37.  
  38. textAttributes = @{
  39. UITextAttributeFont: [UIFont boldSystemFontOfSize:kNavTitleFontSize],
  40. UITextAttributeTextColor: [UIColor whiteColor],
  41. UITextAttributeTextShadowColor: [UIColor clearColor],
  42. UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero],
  43. };
  44. #endif
  45. }
  46. [navigationBarAppearance setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"0x28303b"]] forBarMetrics:UIBarMetricsDefault];
  47. [navigationBarAppearance setTitleTextAttributes:textAttributes];
  48. }
  49.  
  50. 其中上面的版本判断:
  51. FOUNDATION_EXPORT double NSFoundationVersionNumber;
  52.  
  53. #if TARGET_OS_IPHONE
  54. #define NSFoundationVersionNumber_iPhoneOS_2_0 678.24
  55. #define NSFoundationVersionNumber_iPhoneOS_2_1 678.26
  56. #define NSFoundationVersionNumber_iPhoneOS_2_2 678.29
  57. #define NSFoundationVersionNumber_iPhoneOS_3_0 678.47
  58. #define NSFoundationVersionNumber_iPhoneOS_3_1 678.51
  59. #define NSFoundationVersionNumber_iPhoneOS_3_2 678.60
  60. #define NSFoundationVersionNumber_iOS_4_0 751.32
  61. #define NSFoundationVersionNumber_iOS_4_1 751.37
  62. #define NSFoundationVersionNumber_iOS_4_2 751.49
  63. #define NSFoundationVersionNumber_iOS_4_3 751.49
  64. #define NSFoundationVersionNumber_iOS_5_0 881.00
  65. #define NSFoundationVersionNumber_iOS_5_1 890.10
  66. #define NSFoundationVersionNumber_iOS_6_0 992.00
  67. #define NSFoundationVersionNumber_iOS_6_1 993.00
  68. #define NSFoundationVersionNumber_iOS_7_0 1047.20
  69. #define NSFoundationVersionNumber_iOS_7_1 1047.25
  70. #endif

2:判断一张view 是否被加载过用 nil == view.superview

  1. if (nil == view.superview) { //判断一个view 是否被加载过 如果被加载过,它的superview就不会是nil
  2. CGRect frame = scrollView0.frame;
  3. frame.origin.x = frame.size.width * page;
  4. frame.origin.y = ;
  5. view.frame = frame;
  6. [scrollView0 addSubview:view];
  7. }

3:百度地图初始化坐标范围

  1. - (void)viewDidLoad {
  2. [super viewDidLoad];
  3.  
  4. [UIApplication sharedApplication].applicationIconBadgeNumber =;
  5. _mapView=[[BMKMapView alloc] initWithFrame:CGRectMake(, , , )];
  6. BMKCoordinateRegion region; ////表示范围的结构体
  7. region.center.latitude = 24.27;// 中心中
  8. region.center.longitude = 118.06;
  9. region.span.latitudeDelta = 0.1;//经度范围(设置为0.1表示显示范围为0.2的纬度范围)
  10. region.span.longitudeDelta = 0.1;//纬度范围
  11. [_mapView setRegion:region];
  12. [self.baiduView addSubview:_mapView];
  13. }
  14.  
  15. 自定义大头针的图片:
  16.  
  17. - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
  18. {
  19. if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
  20. BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
  21. newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
  22. newAnnotationView.animatesDrop = YES;// 设置该标注点动画显示
  23. newAnnotationView.image = [UIImage imageNamed:@"iphone"]; //把大头针换成别的图片
  24. return newAnnotationView;
  25. }
  26. return nil;
  27. }

4:隐藏键盘

  1. 当前视图上有多个uitextfield时,来隐藏键盘, 先遍历视图的所有子视图来 如果是UITextField就将其设为非第一响应 当然,如果要隐藏子视图上的UITextField的话可以进一步判断viewsubviews的个数,如果大于1则遍历view的子视图,然后作类似操作
  2.  
  3. //隐藏键盘 当前视图上有多个uitextfield
  4.  
  5. for(UIView *view in [self.view subviews])
  6. {
  7. if(view is kindofclass:[UITextField Class])
  8. {
  9. [view resignfirstrespond];
  10. }
  11. }
  12. 直接用 [self.view endEditing:NO]
  13. 直接取消当前Window上的各种view的键盘 [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
  14. 或者使用如下代码
  15. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  16.  
  17. {
  18.  
  19. UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(done:)];
  20.  
  21. tapGestureRecognizer.numberOfTapsRequired = ;
  22.  
  23. [self.view addGestureRecognizer: tapGestureRecognizer]; //只需要点击非文字输入区域就会响应hideKeyBoard
  24.  
  25. return YES;
  26.  
  27. }

5:UIView中的坐标转换

  1. // 将像素point由point所在视图转换到目标视图view中,返回在目标视图view中的像素值
  2. - (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;
  3. // 将像素point从view中转换到当前视图中,返回在当前视图中的像素值
  4. - (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;
  5.  
  6. // 将rect由rect所在视图转换到目标视图view中,返回在目标视图view中的rect
  7. - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;
  8. // 将rect从view中转换到当前视图中,返回在当前视图中的rect
  9. - (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;
  10.  
  11. 例把UITableViewCell中的subview(btn)的frame转换到 controllerA
  12.  
  13. // controllerA 中有一个UITableView, UITableView里有多行UITableVieCell,cell上放有一个button
  14. // 在controllerA中实现:
  15. CGRect rc = [cell convertRect:cell.btn.frame toView:self.view];

  16. CGRect rc = [self.view convertRect:cell.btn.frame fromView:cell];
  17. // 此rc为btn在controllerA中的rect
  18.  
  19. 或当已知btn时:
  20.  
  21. CGRect rc = [btn.superview convertRect:btn.frame toView:self.view];

  22. CGRect rc = [self.view convertRect:btn.frame fromView:btn.superview];
  23.  
  24. 比如:
  25. CGPoint origin = [self convertPoint:CGPointZero toView:[UIApplication sharedApplication].keyWindow];
  26. self0点坐标系,放到keyWindow的坐标系换算一下,获得一个“绝对的”坐标
  27. 一个在父控件中的坐标为0, 其实父控件本来有坐标200, 通过上面可以获得这个200,200

6:弹出一个视图,并有一个背影的视图(大体代码)

  1. - (UIView *)myTapBackgroundView{
  2. if (!_myTapBackgroundView) {
  3. _myTapBackgroundView = ({
  4. UIView *view = [[UIView alloc] initWithFrame:kScreen_Bounds];
  5. view.backgroundColor = [UIColor clearColor];
  6. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeShowing)];
  7. [view addGestureRecognizer:tap];
  8. view;
  9. });
  10. }
  11. return _myTapBackgroundView;
  12. }
  13.  
  14. - (UIView *)myContentView{
  15. if (!_myContentView) {
  16. _myContentView = ({
  17. UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  18. view.backgroundColor = [UIColor whiteColor];
  19. view;
  20. });
  21. }
  22. return _myContentView;
  23. }
  24.  
  25. - (void)changeShowing{
  26. [kKeyWindow endEditing:YES];
  27. if (!_myContentView) {//未载入过
  28. [self loadUIElement];
  29. }
  30. CGPoint origin = [self convertPoint:CGPointZero toView:kKeyWindow];
  31. CGFloat contentHeight = self.isShowing? : kCodeBranchTagButton_ContentHeight;
  32. if (self.isShowing) {//隐藏
  33. self.enabled = NO;
  34. [UIView animateWithDuration:0.3 animations:^{
  35. self.myTapBackgroundView.backgroundColor = [UIColor colorWithWhite: alpha:];
  36. self.myContentView.alpha = ;
  37. self.myContentView.frame = CGRectMake(, origin.y-contentHeight, kScreen_Width, contentHeight);
  38. self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, DEGREES_TO_RADIANS());
  39. } completion:^(BOOL finished) {
  40. [self.myTapBackgroundView removeFromSuperview];
  41. [self.myContentView removeFromSuperview];
  42. self.enabled = YES;
  43. self.isShowing = NO;
  44. }];
  45. }else{//显示
  46. self.myContentView.frame = CGRectMake(, origin.y, kScreen_Width, );
  47. [kKeyWindow addSubview:self.myTapBackgroundView];
  48. [kKeyWindow addSubview:self.myContentView];
  49. self.enabled = NO;
  50. [UIView animateWithDuration:0.3 animations:^{
  51. self.myTapBackgroundView.backgroundColor = [UIColor colorWithWhite: alpha:0.2];
  52. self.myContentView.alpha = 1.0;
  53. self.myContentView.frame = CGRectMake(, origin.y-contentHeight, kScreen_Width, contentHeight);
  54. self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, DEGREES_TO_RADIANS());
  55. } completion:^(BOOL finished) {
  56. self.enabled = YES;
  57. self.isShowing = YES;
  58. }];
  59. }
  60. }
  61.  
  62. 其中:#define kScreen_Bounds [UIScreen mainScreen].bounds
  63. #define kKeyWindow [UIApplication sharedApplication].keyWindow
  64.  
  65. 运用在项目中一个下拉菜单:

/**

*  @author wujunyang, 15-05-13 14:05:12

*

*  @brief  初始化背景视图

*  @return <#return value description#>

*/

- (UIView *)myTapBackgroundView{

if (!_myTapBackgroundView) {

_myTapBackgroundView = ({

UIView *view = [[UIView alloc] initWithFrame:SCREENFRAME];

view.backgroundColor = [UIColor clearColor];

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeShowing)];

[view addGestureRecognizer:tap];

view;

});

}

return _myTapBackgroundView;

}

/**

*  @author wujunyang, 15-05-13 14:05:25

*

*  @brief  初始化弹出视图

*  @return <#return value description#>

*/

- (UIView *)myContentView{

if (!_myContentView) {

_myContentView = ({

UIView *view = [[UIView alloc] initWithFrame:CGRectZero];

view.backgroundColor = [UIColor whiteColor];

view;

});

}

return _myContentView;

}

/**

*  @author wujunyang, 15-05-13 14:05:39

*

*  @brief  加载xib文件到弹出视图里面

*/

- (void)loadUIElement{

self.myTapBackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0];

self.homeMyselfMenuView=[HomeMyselfMenuView instanceHomeMyselfMenuView];

self.homeMyselfMenuView.frame = CGRectMake(0, 0, 0, 0);//注意其宽高

[self.myContentView addSubview:self.homeMyselfMenuView];

}

/**

*  @author wujunyang, 15-05-13 14:05:07

*

*  @brief  控制视图的显示及隐藏

*/

- (void)changeShowing{

if (!_myContentView) {

[self loadUIElement];

}

CGFloat contentHeight = self.isShowing? 0: STATUSNAVBARHEIGHT;

if (self.isShowing) {//隐藏

[self narrowTransToView:NO];

[UIView animateWithDuration:0.3 animations:^{

self.myTapBackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0];

self.myContentView.alpha = 0;

self.myContentView.frame = CGRectMake(0,0, SCREEN_WIDTH, contentHeight);

} completion:^(BOOL finished) {

[self.myTapBackgroundView removeFromSuperview];

[self.myContentView removeFromSuperview];

self.isShowing = NO;

}];

}else{//显示

[self narrowTransToView:YES];

self.myContentView.frame = CGRectMake(0, STATUSNAVBARHEIGHT, SCREEN_WIDTH, 0);

[self.view addSubview:self.myTapBackgroundView];

[self.view addSubview:self.myContentView];

[UIView animateWithDuration:0.3 animations:^{

self.myTapBackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];

self.myContentView.alpha = 1.0;

self.myContentView.frame = CGRectMake(0, STATUSNAVBARHEIGHT, SCREEN_WIDTH, contentHeight);

} completion:^(BOOL finished) {

self.isShowing = YES;

}];

}

}

/**

*  @author wujunyang, 15-05-13 15:05:22

*

*  @brief  视图区缩放

*  @param isNarrow 是否缩放

*/

-(void)narrowTransToView:(BOOL)isNarrow

{

_contentView.transform=CGAffineTransformIdentity;

[UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];

if(isNarrow)

{

_contentView.transform=CGAffineTransformMakeScale(0.9f, 0.9f);

}

else

{

_contentView.transform=CGAffineTransformMakeScale(1.0f, 1.0f);

}

[UIView commitAnimations];

}

IOS客户端Coding项目记录(五)的更多相关文章

  1. IOS客户端Coding项目记录导航

    IOS客户端Coding项目记录(一) a:UITextField设置出现清除按键 b:绘画一条下划线  表格一些设置 c:可以定义表头跟底部视图(代码接上面) d:隐藏本页的导航栏 e:UIEdge ...

  2. IOS客户端Coding项目记录(四)

    1:打开Xcode,然后闪退,报加载某库出现异常 如/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolc ...

  3. IOS客户端Coding项目记录(一)

    1:UITextField设置出现清除按键 self.textField.clearButtonMode = UITextFieldViewModeWhileEditing; 说明: UITextFi ...

  4. IOS客户端Coding项目记录(六)

    1:获取某一行的坐标 UITableViewCell *cell = [_myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow: ...

  5. IOS客户端Coding项目记录(三)

    18:图片视图几种填充样式 _imgView.contentMode = UIViewContentModeScaleAspectFill; 如下: typedef NS_ENUM(NSInteger ...

  6. IOS客户端Coding项目记录(二)

    9:第三方插件整理 JSON转实体:jsonModel https://github.com/icanzilb/JSONModel/ 美化按键:BButton https://github.com/m ...

  7. 开源项目在真机调试(Coding iOS 客户端为例)

    一.前言 iOS 13学习系列:如何在github下载开源项目到本地(Coding iOS 客户端为例)已经把 Coding iOS 客户端源码下载到本地. 但项目进行真机调试遇到很多问题. 二.问题 ...

  8. 如何在github下载开源项目到本地(Coding iOS 客户端为例)

    一.前言 以 Coding iOS 客户端 为例讲解如何在github下载开源项目到本地 github地址:https://github.com/Coding/Coding-iOS 二.分析 根据项目 ...

  9. “快的打车”创始人陈伟星的新项目招人啦,高薪急招Java服务端/Android/Ios 客户端研发工程师/ mysql DBA/ app市场推广专家,欢迎大家加入我们的团队! - V2EX

    "快的打车"创始人陈伟星的新项目招人啦,高薪急招Java服务端/Android/Ios 客户端研发工程师/ mysql DBA/ app市场推广专家,欢迎大家加入我们的团队! - ...

随机推荐

  1. 【转载】S2SH

    说说最多人用的SSH或SSI吧,现在用的比较多的应该就是struts2.x+spring3.X+hibernate4.X或hibernate3.X了吧,mybatis用的人也有,方便有DBA的公司. ...

  2. emacs工程管理,cedet ede插件自动构建Make,Automake

    鉴于自己一直都是在做客户端开发方面的工作,服务端很多知识都随着时间淡忘了,最近有一个计划,用一些时间补一下基础.所以早上很早就起床,花了一点时间大致浏览了一下BSD socket的相关API,然后用G ...

  3. MyBatis知多少(16)MyBatis映射

    之前我们详细地讨论了MyBatis背后的设计理念以及iBATIS框架是如何产生的.也说明了MyBatis是一个混合型解决方案,它从处理关系数据库的其他不同方法那里借鉴了许多思想.那么MyBatis到底 ...

  4. codeforce No to Palindromes!(枚举)

    /* 题意:给定一个字符串中没有任何长度>1的回文子串!求按照字典序的该串的下一个字符串 也不包含长度>1的任何回文子串! 思路:从最低位进行枚举,保证第i位 不与 第 i-1位和第 i- ...

  5. [Python] Remote debugging by Pycharm

    From: http://blog.csdn.net/u013088062/article/details/50170551 虚拟环境配置 配置远程解释器 设想这样一种情况,你在一个平台上操作你的工程 ...

  6. [Node.js] Express的测试覆盖率

    原文地址:http://www.moye.me/2014/12/03/express_coverage/ 引子 有群友问到Express怎么做 单元测试/覆盖率测试,这是上篇所遗漏的,特此补上 Exp ...

  7. 实用手册:130+ 提高开发效率的 vim 常用命令

    Vim 是从 vi 发展出来的一个文本编辑器.代码补完.编译及错误跳转等方便编程的功能特别丰富,在程序员中被广泛使用.和 Emacs 并列成为类 Unix 系统用户最喜欢的编辑器.这里收录了130+程 ...

  8. iOS-微信支付(订单号重复的问题)

    1. 官方文档中说过同一笔交易不能多次提交,出现这个错误让核实商户订单号是否重复提交,但是有些情况下是需要重复提交的,比如:用户微信支付的时候没有付款,直接取消了,那么订单如果已经创建了,在订单中心就 ...

  9. Android 学习笔记 Service

    PS:前几篇的内容光是上代码了,也没有细细的讲解..感觉这样写很不好..因此还是多一些讲解吧... 学习内容: 1.了解Service... 2.Service的启动与停止.. 3.绑定与取消绑定Se ...

  10. 学习android开发笔记

    最近重点看了几个android工程的源代码,有几点疑问 1:为什么android客户端游戏要开启n个线程,而且通常每个线程的操作只有i++: 2:为什么很多列表在游戏逻辑和绘制逻辑里没有做同步: 3: ...