iOS应用开发之NavBar和TarBar使用技巧
安安 2017-10-31 来源 :网络 阅读 811 评论 0

摘要:本篇IOS应用开发教程将为大家讲解IOS编程的知识点,看完这篇文章会让你对IOS编程的知识点有更加清晰的理解和运用。

本篇IOS应用开发教程将为大家讲解IOS编程的知识点,看完这篇文章会让你对IOS编程的知识点有更加清晰的理解和运用。

 

1 改变NavBar颜色:选中Navigation Bar 的Tint属性。选中颜色。

2 隐藏“back”按钮: self.navigationItem.hidesBackButton = YES;

3 隐藏”NavBar” : self.navigationController.navigationBarHidden = YES;

4 可以不用MainWindow.xib创建的Navigation。在每个view上自定义。

需要把每个控制页都加上以下代码来隐藏nav:

-(void)viewWillAppear:(BOOL)animated

{self.navigationController.navigationBarHidden = YES;//显示"NavBar"

}

然后在每个控制页xib自己添加Navigation Bar。添加所需BarButtonItem按钮。

5 页面跳转隐藏tarbar :

HomeDetailViewController *detailview = [[HomeDetailViewController alloc] initWithNibName:@"HomeDetailView" bundle:nil];  

detailview.hidesBottomBarWhenPushed = YES;//隐藏tarbar  

[self.navigationController pushViewController:detailview animated:YES];  

[detailview     release];

6 页面返回:

[self.navigationController popViewControllerAnimated:YES];

7 默认选中tabbar为第一个view:

TabBarController.selectedIndex= 0;

其他:

8 已知两地经纬度 计算两地之间的距离:  //    地图显示当前位置:  

    mapView.showsUserLocation=YES;  

    CLLocationManager *locationManager = [[CLLocationManager alloc] init];//创建位置管理器  

    locationManager.delegate=self;//设置代理  

    locationManager.desiredAccuracy=kCLLocationAccuracyBest;//指定需要的精度级别为最佳精度  

    locationManager.distanceFilter=1000.0f;//设置距离筛选器为任何移动都要发送更新  

    [locationManager startUpdatingLocation];//启动位置管理器  

    MKCoordinateSpan theSpan;  

    //地图的范围 越小越精确  

    theSpan.latitudeDelta=0.05;  

    theSpan.longitudeDelta=0.05;  

    MKCoordinateRegion theRegion;  

    theRegion.center=[[locationManager location] coordinate];  

    theRegion.span=theSpan;  

    [mapView setRegion:theRegion];  

    [locationManager release];  

 

    MKUserLocation *usrLoc=mapView.userLocation;  

    CLLocationCoordinate2D usrCoordinate=usrLoc.location.coordinate;  

    NSLog(@"la==%f lo==%f",usrCoordinate.latitude,usrCoordinate.longitude);  

//   已知两点的经纬度,计算出两地距离:  

    CLLocation *location1 = [[[CLLocation alloc] initWithLatitude:usrCoordinate.latitude longitude:usrCoordinate.longitude] autorelease];  

    CLLocation *location2 = [[[CLLocation alloc] initWithLatitude:36.676445 longitude:117.106793] autorelease];

    NSLog(@"JULI====%.0f km", [location1 distanceFromLocation:location2]);//4502

9 取小数点后两位(四舍五入),输出:

NSLog(@”%.02f km”,4478.442312);

10 调用打电话API :

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10010"]];

使用这种方式拨打电话时,当用户结束通话后,iphone界面会停留在电话界面。

用如下方式,可以使得用户结束通话后自动返回到应用:

UIWebView*callWebview =[[UIWebView alloc] init];  

    NSURL *telURL =[NSURL URLWithString:@"tel:10086"];// 貌似tel:// 或者 tel: 都行  

    [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];  

    //记得添加到view上  

    [self.view addSubview:callWebview];

11 调用 SMS发短信:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://15315310992"]];

12 调用自带 浏览器 safari

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"//www.baidu.com"]];

13 在一个程序里打开另一个程序:

首先:plist里添加URL types   点开里边的Item0  添加URLSchemes  打开Item0 输入sinaWeibo

然后在需要调用的地方:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sinaWeibo://*"]];

https://itunes.apple.com/cn/app/qq-2012/id444934666?mt=8

14 双引号转义:

用 \” 表示 双引号

15 设置按钮按下换图片 松开还是原图

//                [danxuan setImage:[UIImage imageNamed:@"exercise_option_n.png"] forState:UIControlStateNormal];  

                //这个是设置按下的图片,松开就是上面的图片  

//               [danxuan setImage:[UIImage imageNamed:@"exercise_option_s.png"] forState:UIControlEventTouchDragOutside];

16  判断数组中是否存在某元素:

BOOL isValue=[keyArray containsObject:@"aaa"];

17 Nav添加button

UIButton *btnBack = [ABUtil createNavigationCtrollerRoundedRectBtn:Localized(@"取消")];  

    [btnBack addTarget:self  

                action:@selector(tapLeftBarButton)  

      forControlEvents:UIControlEventTouchUpInside];  

    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnBack];  

    self.navigationItem.leftBarButtonItem = leftBarButtonItem;  

    [btnBack release];  

    [leftBarButtonItem release]

 

希望这篇文章可以帮助到你。总之,同学们,你想要的职坐标IOS频道都能找到!

本文由 @安安 发布于职坐标。未经许可,禁止转载。
喜欢 | 1 不喜欢 | 0
看完这篇文章有何感觉?已经有1人表态,100%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程