主控制器
导一下#import "MapViewController.h"头文件
@interface ViewController
()<UITableViewDelegate,UITableViewDataSource> {
UITableView *tab;
UIView *leftview;
UIView *mainv;
NSArray *arr;
BOOL isSelect;
} @end@implementation ViewController
-
(void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title=@“滴滴打车”;UIBarButtonItem *leftl=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@“ke1”] style:UIBarButtonItemStyleDone target:self action:@selector(click)];
self.navigationItem.leftBarButtonItem=leftl;
arr=@[@“订单”,@“钱包”,@“客服”,@“我的”];
//创建左侧视图
leftview=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 260, self.view.frame.size.height)];
[self.view addSubview:leftview];
//主视图
mainv=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
UIImageView *img11=[[UIImageView alloc]initWithFrame:CGRectMake(0, 90, self.view.frame.size.width, self.view.frame.size.height-200)];
img11.image=[UIImage imageNamed:@“11”];
[mainv addSubview:img11];
mainv.backgroundColor=[UIColor whiteColor];
[self.view addSubview:mainv];tab=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, 260, self.view.frame.size.height) style:UITableViewStylePlain];
tab.showsHorizontalScrollIndicator=NO;
tab.delegate=self;
tab.dataSource=self;
[leftview addSubview:tab];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
-(NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section1) {
return 4;
}else
{
return 1;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *str=@“1”;
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:str];
if (cellnil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
}
if (indexPath.section= =0) {
UIImageView *_img=[[UIImageView alloc]initWithFrame:CGRectMake(50, 20, 150, 150) ];
_img.image=[UIImage imageNamed:@“arr1”];
[cell addSubview:_img];
}else if (indexPath.section==1)
{
UILabel *labI=[[UILabel alloc]initWithFrame:CGRectMake(70,180, 260, 30)];
labI.text=arr[indexPath.row];
labI.font=[UIFont systemFontOfSize:24];
[cell addSubview:labI];
NSArray *arr1=@[@“ding1”,@“qian1”,@“ke1”,@“she1”];
UIImageView *_img1=[[UIImageView alloc]initWithFrame:CGRectMake(10, 170, 50, 50) ];
_img1.image=[UIImage imageNamed:arr1[indexPath.row]];
[cell addSubview:_img1];
}
return cell;
}
-(void )click//左侧left
{
if (isSelect == NO) {
// (NSTimeInterval) 时间间隔
[UIView animateWithDuration:0.5 animations:^{
//移动视图
self.navigationController.navigationBar.transform = CGAffineTransformMakeTranslation(260, 0);
//移动MainView
mainv.transform = CGAffineTransformMakeTranslation(260, 0);
}];
isSelect = YES;
}else{
//恢复原位
[UIView animateWithDuration:0.5 animations:^{
//恢复原位 导航条
self.navigationController.navigationBar.transform = CGAffineTransformIdentity;
//恢复leftView
leftview.transform = CGAffineTransformIdentity;
//恢复mainView
mainv.transform = CGAffineTransformIdentity;
}];
isSelect = NO;
}
}
//点击空白处发生跳转
-
(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
MapViewController *mapVa=[[MapViewController alloc]init];
[self.navigationController pushViewController:mapVa animated:YES];
}
@end
插入链接与图片
链接: [link](https://导入本地的框架
地图的内容
ps://导入privacy ——Location…
#import “MapViewController.h”
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h> @interface MapViewController ()
@property(nonatomic,strong)MKMapView*mapView;
@property(strong)CLLocationManager *locManager;@end
-
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.self.mapView=[[MKMapView alloc]initWithFrame:self.view.frame];
// self.mapView.mapType=MKMapTypeHybrid;
//卫星加平面样式
self.mapView.mapType=MKMapTypeStandard;//平面样式
[self.view addSubview:self.mapView];
UIButton *currentbut=[UIButton buttonWithType:UIButtonTypeCustom];
currentbut.backgroundColor=[UIColor cyanColor];
currentbut.frame=CGRectMake(self.view.frame.size.width-80, self.view.frame.size.height-90, 50, 50);
//按钮位置
[currentbut setTitle:@"按钮" forState:UIControlStateNormal];
[currentbut addTarget:self action:@selector(abc:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:currentbut];
//请求发送位置权限
self.locManager=[[CLLocationManager alloc]init];
self.locManager.delegate=self;
//申请授权
[self.locManager requestWhenInUseAuthorization];
}
-(void)abc:(id)sender
{
//开始获取位置信息 调用此方法后 协议中的方法开始执行
[self.locManager startUpdatingLocation];
}
//获取到位置后触发的回调方法,具体的方法
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
// 获取当前位置
CLLocation *curloc=[locations lastObject];
CLLocationCoordinate2D curCoor=curloc.coordinate;
NSLog(@“经度%g,纬度%g”,curCoor.longitude,curCoor.latitude);
//定位一次即刻停止
manager.delegate=nil;
//让地图的显示区缩小至100米
MKCoordinateRegion region=MKCoordinateRegionMakeWithDistance(curCoor, 100, 100);
[self.mapView setRegion:region animated:YES];
// 反向地址解析,将经纬度转换为地址字符串
CLGeocoder*geocoder=[[CLGeocoder alloc]init];
[geocoder reverseGeocodeLocation:curloc completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
// 获取其中一个
CLPlacemark*place=[placemarks lastObject];
//做一个大头针 钉在当前位置上
MKPointAnnotation *point=[[MKPointAnnotation alloc]init];
point.title=[NSString stringWithFormat:@"我的位置:%@",place.name];
// 设置大头针的经纬度
point.coordinate=curCoor;
// 添加到地图上
[self.mapView addAnnotation:point];
}];
}
(nullable MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation{
static NSString *iden=@“pin”;
MKPinAnnotationView *pin=[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:iden];
pin.canShowCallout=YES;
return pin;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
https://www.jianshu.com/p/0d4c4dc529ea
https://github.com/a122273328/NaviDemo