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

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor]; //设置导航条样式
[self customizeInterface]; if ([Login isLogin]) {
[self setupTabViewController];
}else{
[UIApplication sharedApplication].applicationIconBadgeNumber = ;
[self setupLoginViewController];
}
[self.window makeKeyAndVisible];
return YES;
} - (void)customizeInterface {
//设置Nav的背景色和title色
UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
NSDictionary *textAttributes = nil;
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
[navigationBarAppearance setTintColor:[UIColor whiteColor]];//返回按钮的箭头颜色
[[UITextField appearance] setTintColor:[UIColor colorWithHexString:@"0x3bbc79"]];//设置UITextField的光标颜色
[[UITextView appearance] setTintColor:[UIColor colorWithHexString:@"0x3bbc79"]];//设置UITextView的光标颜色
[[UISearchBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"0xe5e5e5"]] forBarPosition: barMetrics:UIBarMetricsDefault]; textAttributes = @{
NSFontAttributeName: [UIFont boldSystemFontOfSize:kNavTitleFontSize],
NSForegroundColorAttributeName: [UIColor whiteColor],
};
} else {
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
[[UISearchBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"0xe5e5e5"]]]; textAttributes = @{
UITextAttributeFont: [UIFont boldSystemFontOfSize:kNavTitleFontSize],
UITextAttributeTextColor: [UIColor whiteColor],
UITextAttributeTextShadowColor: [UIColor clearColor],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero],
};
#endif
}
[navigationBarAppearance setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"0x28303b"]] forBarMetrics:UIBarMetricsDefault];
[navigationBarAppearance setTitleTextAttributes:textAttributes];
} 其中上面的版本判断:
FOUNDATION_EXPORT double NSFoundationVersionNumber; #if TARGET_OS_IPHONE
#define NSFoundationVersionNumber_iPhoneOS_2_0 678.24
#define NSFoundationVersionNumber_iPhoneOS_2_1 678.26
#define NSFoundationVersionNumber_iPhoneOS_2_2 678.29
#define NSFoundationVersionNumber_iPhoneOS_3_0 678.47
#define NSFoundationVersionNumber_iPhoneOS_3_1 678.51
#define NSFoundationVersionNumber_iPhoneOS_3_2 678.60
#define NSFoundationVersionNumber_iOS_4_0 751.32
#define NSFoundationVersionNumber_iOS_4_1 751.37
#define NSFoundationVersionNumber_iOS_4_2 751.49
#define NSFoundationVersionNumber_iOS_4_3 751.49
#define NSFoundationVersionNumber_iOS_5_0 881.00
#define NSFoundationVersionNumber_iOS_5_1 890.10
#define NSFoundationVersionNumber_iOS_6_0 992.00
#define NSFoundationVersionNumber_iOS_6_1 993.00
#define NSFoundationVersionNumber_iOS_7_0 1047.20
#define NSFoundationVersionNumber_iOS_7_1 1047.25
#endif

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

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

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

- (void)viewDidLoad {
[super viewDidLoad]; [UIApplication sharedApplication].applicationIconBadgeNumber =;
_mapView=[[BMKMapView alloc] initWithFrame:CGRectMake(, , , )];
BMKCoordinateRegion region; ////表示范围的结构体
region.center.latitude = 24.27;// 中心中
region.center.longitude = 118.06;
region.span.latitudeDelta = 0.1;//经度范围(设置为0.1表示显示范围为0.2的纬度范围)
region.span.longitudeDelta = 0.1;//纬度范围
[_mapView setRegion:region];
[self.baiduView addSubview:_mapView];
} 自定义大头针的图片: - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
newAnnotationView.animatesDrop = YES;// 设置该标注点动画显示
newAnnotationView.image = [UIImage imageNamed:@"iphone"]; //把大头针换成别的图片
return newAnnotationView;
}
return nil;
}

4:隐藏键盘

当前视图上有多个uitextfield时,来隐藏键盘, 先遍历视图的所有子视图来 如果是UITextField就将其设为非第一响应 当然,如果要隐藏子视图上的UITextField的话可以进一步判断view的subviews的个数,如果大于1则遍历view的子视图,然后作类似操作

//隐藏键盘  当前视图上有多个uitextfield

for(UIView *view in [self.view subviews])
{
if(view is kindofclass:[UITextField Class])
{
[view resignfirstrespond];
}
}
直接用 [self.view endEditing:NO]
直接取消当前Window上的各种view的键盘 [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
或者使用如下代码
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(done:)]; tapGestureRecognizer.numberOfTapsRequired = ; [self.view addGestureRecognizer: tapGestureRecognizer]; //只需要点击非文字输入区域就会响应hideKeyBoard return YES; }

5:UIView中的坐标转换

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

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

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

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

- (UIView *)myTapBackgroundView{
if (!_myTapBackgroundView) {
_myTapBackgroundView = ({
UIView *view = [[UIView alloc] initWithFrame:kScreen_Bounds];
view.backgroundColor = [UIColor clearColor];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeShowing)];
[view addGestureRecognizer:tap];
view;
});
}
return _myTapBackgroundView;
} - (UIView *)myContentView{
if (!_myContentView) {
_myContentView = ({
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.backgroundColor = [UIColor whiteColor];
view;
});
}
return _myContentView;
} - (void)changeShowing{
[kKeyWindow endEditing:YES];
if (!_myContentView) {//未载入过
[self loadUIElement];
}
CGPoint origin = [self convertPoint:CGPointZero toView:kKeyWindow];
CGFloat contentHeight = self.isShowing? : kCodeBranchTagButton_ContentHeight;
if (self.isShowing) {//隐藏
self.enabled = NO;
[UIView animateWithDuration:0.3 animations:^{
self.myTapBackgroundView.backgroundColor = [UIColor colorWithWhite: alpha:];
self.myContentView.alpha = ;
self.myContentView.frame = CGRectMake(, origin.y-contentHeight, kScreen_Width, contentHeight);
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, DEGREES_TO_RADIANS());
} completion:^(BOOL finished) {
[self.myTapBackgroundView removeFromSuperview];
[self.myContentView removeFromSuperview];
self.enabled = YES;
self.isShowing = NO;
}];
}else{//显示
self.myContentView.frame = CGRectMake(, origin.y, kScreen_Width, );
[kKeyWindow addSubview:self.myTapBackgroundView];
[kKeyWindow addSubview:self.myContentView];
self.enabled = NO;
[UIView animateWithDuration:0.3 animations:^{
self.myTapBackgroundView.backgroundColor = [UIColor colorWithWhite: alpha:0.2];
self.myContentView.alpha = 1.0;
self.myContentView.frame = CGRectMake(, origin.y-contentHeight, kScreen_Width, contentHeight);
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, DEGREES_TO_RADIANS());
} completion:^(BOOL finished) {
self.enabled = YES;
self.isShowing = YES;
}];
}
} 其中:#define kScreen_Bounds [UIScreen mainScreen].bounds
#define kKeyWindow [UIApplication sharedApplication].keyWindow 运用在项目中一个下拉菜单:

/**

*  @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. WCF 遇到的问题

    1.只有项目的net版本2.0以上的才可以引用到wcf的类库 2.HTTP 错误 404.17 - Not Found  映射问题   WCF服务建立好,提示这个错误,缺少映射问题,要将应用程序池和项 ...

  2. `fw服务端非完整` 工程开发初期的工作

    前面写到了一些关于cocos2dx在开发中的一些模块以及一些解决方法,那些都属于本人的个人简介和个人倾向的解决方案.最近这几天我完善了一下ui解析的部分,当然也只是抽出一点点时间去做的这件事情.我添加 ...

  3. 爆料喽!!!开源日志库Logger的使用秘籍

    日志对于开发来说是非常重要的,不管是调试数据查看.bug问题追踪定位.数据信息收集统计,日常工作运行维护等等,都大量的使用到.今天介绍著名开源日志库Logger的使用,库的地址:https://git ...

  4. Web Component--01. 简介

    Web Components 是什么? Web Components是W3C定义的新标准,它给了前端开发者扩展浏览器标签的能力,可以自由的定制组件,更好的进行模块化开发,彻底解放了前端开发者的生产力. ...

  5. 云计算之路-阿里云上:消灭“黑色n秒”第二招——给w3wp进程指定CPU核

    虽然昨天的第一招失败了,但是从失败中我们学到了与多核CPU相关的Processor Affinity(处理器关联)的知识. 既然我们可以让.NET程序的不同线程运行于指定的CPU核,那是不是也可以让I ...

  6. css实现高度不固定的div元素模块在页面中水平垂直居中

    <!DOCTYPE html><html>    <head>        <title>Laravel</title> <link ...

  7. Android 学习笔记之AndBase框架学习(三) 使用封装好的函数完成Http请求..

    PS:踏踏实实走好每一步... 学习内容: 1.使用AndBase框架实现无参Http Get请求... 2.使用AndBase框架实现有参Http Post请求... 3.使用AndBase框架实现 ...

  8. javascript中的数组扩展(一)

     javascript中的数组扩展(一) 随着学习的深入,发现需要学习的关于数组的内容也越来越多,后面将会慢慢归纳,有的是对前面的强化,有些则是关于前面的补充. 一.数组的本质    数组是按照次序排 ...

  9. Sql Server来龙去脉系列之一 目录篇

    从工作一直到现在都没怎么花功夫深入学习下Sql Server数据库,在使用Sql Server时90%的时间基本上都是在接触T-SQL,所以数据库这块基本上属于菜鸟级别.至于数据库的底层框架以及运行机 ...

  10. C#设计模式——工厂方法模式(Factory Method Pattern)

    一.概述在软件系统中,经常面临着“某个对象”的创建工作,由于需求的变化,这个对象的具体实现经常面临着剧烈的变化,但是它却拥有比较稳定的接口.如何应对这种变化?如何提供一种封装机制来隔离出“这个易变对象 ...