ASdas
1.M在AppDelegate.h导入ViewController.h
2.V在ViewController.h定义五个控制器并创建文件,继承于UIViewCelegate
3.C中创建一个MapUIkit.h
并导入系统类
#import <MapKit/MapKit.h>
导入获取经纬度类
#import <CoreLocation/CoreLocation.h>
定义协议MKMapViewDelegate和CLLocationManagerDelegate
创建两个地图对象 MKMapView和CLLocationManager
- (void)viewDidLoad {
[super viewDidLoad];
//设置导航标题
self.navigationItem.title =self.provie;
//设置右侧按钮
//self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"省会定位" style:UIBarButtonItemStyleDone target:self action:@selector(YOU:)];
//实例化
self.MapView = [[MKMapView alloc] initWithFrame:self.view.frame];
//设置代理
self.MapView.delegate=self;
//设置地图样式
self.MapView.mapType = MKMapTypeStandard;
//加载视图
[self.viewaddSubview:self.MapView];
//设置按钮
UIButton *butt = [UIButton buttonWithType:UIButtonTypeCustom];
//设置
butt.frame=CGRectMake(40,600,50,50);
//添加文字
[buttsetTitle:@"当前位置" forState:UIControlStateNormal];
butt.titleLabel.font= [UIFontsystemFontOfSize:10];
//添加点击事件
[buttaddTarget:self action:@selector(dian:) forControlEvents:UIControlEventTouchUpInside];
butt.layer.masksToBounds = YES;
butt.layer.cornerRadius = 25;
butt.backgroundColor= [UIColorgreenColor];
//添加视图
[self.viewaddSubview:butt];
//实例化经纬度类
self.lomanger = [[CLLocationManager alloc] init];
//申请用户授权用户进入后台不在授权
[self.lomanger requestWhenInUseAuthorization];
}
- (void)YOU:(id)seb{
//
CLGeocoder *g = [[CLGeocoder alloc] init];
//将地址字符串转换为位置的经纬度
[ggeocodeAddressString:self.proviecompletionHandler:^(NSArray *_Nullableplacemarks,NSError*_Nullableerror) {
//获取位置随便展示在地图上
CLPlacemark*place = [placemarkslastObject];
//获取位置
CLLocation*loc =place.location;
CLLocationCoordinate2D coor = loc.coordinate;
//定位
MKPointAnnotation *anne = [[MKPointAnnotation alloc] init];
//设置挫钉
anne.coordinate= coor;
//回到主线程
dispatch_async(dispatch_get_main_queue(), ^{
//设置让地图显示区域缩小
MKCoordinateRegion rgin =MKCoordinateRegionMakeWithDistance(coor, 10, 10);
//添加到视图
[self.MapViewsetRegion:rgin];
[self.MapViewaddAnnotation:anne];
});
}];
}
//实现点击方法
- (void)dian:(id)sender{
//设置代理
self.lomanger.delegate=self;
//开始获取位置信息 调用此方法后协议中的方法才会执行
[self.lomanger startUpdatingLocation];
}
//实现代理方法
- (void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray *)locations{
//创建对象获取当前获取最后一个元素
CLLocation*curloc = [locationslastObject];
//创建结构体 获取经纬度
CLLocationCoordinate2D curCoor = curloc.coordinate;
self.lomanger.delegate=nil;
//输出经纬度
NSLog(@"经度%g,纬度%g",curCoor.longitude,curCoor.latitude);
//设置让地图显示区域缩小
MKCoordinateRegion rgin =MKCoordinateRegionMakeWithDistance(curCoor, 30, 30);
//设置动画并添加
[self.MapView setRegion:rgin animated:YES];
//将地址经纬度转换为字符串
CLGeocoder*Geder = [[CLGeocoderalloc]init];
//设置方法
[GederreverseGeocodeLocation:curloccompletionHandler:^(NSArray *_Nullableplacemarks,NSError*_Nullableerror) {
//创建异步队列回到主线程
dispatch_async(dispatch_get_main_queue(), ^{
//获取最后一个经纬度转换为字符串
CLPlacemark*place = [placemarksfirstObject];
//设置大头针
MKPointAnnotation *pino = [[MKPointAnnotation alloc] init];
//将获取的地址名字给大头针
pino.title= place.name;
//设置大头针的位置
pino.coordinate= curCoor;
//添加到地图上
[self.MapViewaddAnnotation:pino];
});
}];
}
//实现大头针点击事件
- (nullableMKAnnotationView*)mapView:(MKMapView*)mapView viewForAnnotation:(id)annotation{
//从MAPView找一块可用的内存
MKPinAnnotationView *kl =[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"1"];
//设置动画
kl.animatesDrop = YES;
//设置
kl.canShowCallout = YES;
//返回内容
returnkl;
}
4.在第一个文件中导入MapUIkit.h,并写协议UITableViewDelegate和UITableViewDataSource
在协议中定义五个属性
UITableView * tbv;
UIScrollView *scro;
UIPageControl *pag;
NSTimer*timer;
intk;
- (void)viewDidLoad {
// Do any additional setup after loading the view.
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"周边" style:UIBarButtonItemStylePlain target:self action:@selector(dian)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"北京" style:UIBarButtonItemStylePlain target:self action:nil];
self.navigationController.navigationBar.backgroundColor = [UIColor yellowColor];
self.view.backgroundColor = [UIColor whiteColor];
UISearchBar * sea = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
sea.placeholder =@"请输入搜索的商品";
self.navigationItem.titleView = sea;
tbv = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
tbv.dataSource = self;
tbv.delegate=self;
[self.view addSubview:tbv];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{
return 2;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
if(section==0) {
return3;
}else{
return1;
}
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"2"];
if(!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"2"];
}
if(indexPath.section==0) {
if(indexPath.row==0) {
tbv.rowHeight=200;
// 初始化滚动式图
scro= [[UIScrollViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,200)];
// 设置滚动范围
scro.contentSize = CGSizeMake(3 * self.view.frame.size.width, 0);
// 禁用弹簧效果
scro.bounces=NO;
// 禁用水平滚动
scro.showsHorizontalScrollIndicator = NO;
// 设置整页滚动
scro.pagingEnabled=YES;
// 设置代理
scro.delegate=self;
// 设置滚动图片
for(inti =0; i <3; i++){
// 设置图片数组
NSArray*arr =@[@"1",@"2",@"3"];
UIImageView*imgV = [[UIImageViewalloc]initWithFrame:CGRectMake(i *self.view.frame.size.width,0,self.view.frame.size.width,200)];
// 加载图片
imgV.image= [UIImageimageNamed:arr[i]];
// 添加到滚动视图中
[scroaddSubview:imgV];
}
// 添加到cell中
[celladdSubview:scro];
// 设置豆豆
pag= [[UIPageControlalloc]initWithFrame:CGRectMake(90,95,150,25)];
// 设置豆豆的数量
pag.numberOfPages=3;
// 设置豆豆的颜色
pag.currentPageIndicatorTintColor = [UIColor orangeColor];
pag.pageIndicatorTintColor = [UIColor whiteColor];
// 添加到单元格中
[celladdSubview:pag];
// 创建定时器
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(aaa) userInfo:nil repeats:YES];
}elseif(indexPath.row==1){
tbv.rowHeight=100;
UIImageView* ima = [[UIImageViewalloc]initWithFrame:CGRectMake(40,10,50,50)];
ima.image= [UIImageimageNamed:@"5"];
ima.layer.masksToBounds=YES;
ima.layer.cornerRadius=25;
[celladdSubview: ima];
UILabel* lab = [[UILabelalloc]initWithFrame:CGRectMake(40,70,60,20)];
lab.text=@"全部任务";
lab.font= [UIFontsystemFontOfSize:10];
[celladdSubview:lab];
UIImageView* ima1 = [[UIImageViewalloc]initWithFrame:CGRectMake(140,10,50,50)];
ima1.image= [UIImageimageNamed:@"6"];
ima1.layer.masksToBounds=YES;
ima1.layer.cornerRadius=25;
[celladdSubview: ima1];
UILabel* lab1 = [[UILabelalloc]initWithFrame:CGRectMake(140,70,60,20)];
lab1.text=@"全部任务";
lab1.font= [UIFontsystemFontOfSize:10];
[celladdSubview:lab1];
UIImageView* ima2 = [[UIImageViewalloc]initWithFrame:CGRectMake(220,10,50,50)];
ima2.image= [UIImageimageNamed:@"7"];
ima2.layer.masksToBounds=YES;
ima2.layer.cornerRadius=25;
[celladdSubview: ima2];
UILabel* lab2 = [[UILabelalloc]initWithFrame:CGRectMake(220,70,60,20)];
lab2.text=@"全部任务";
lab2.font= [UIFontsystemFontOfSize:10];
[celladdSubview:lab2];
UIImageView* ima3 = [[UIImageViewalloc]initWithFrame:CGRectMake(300,10,50,50)];
ima3.image= [UIImageimageNamed:@"8"];
ima3.layer.masksToBounds=YES;
ima3.layer.cornerRadius=25;
[celladdSubview: ima3];
UILabel* lab3 = [[UILabelalloc]initWithFrame:CGRectMake(300,70,60,20)];
lab3.text=@"全部任务";
lab3.font= [UIFontsystemFontOfSize:10];
[celladdSubview:lab3];
}else{
tbv.rowHeight=100;
UIImageView* ima = [[UIImageViewalloc]initWithFrame:CGRectMake(40,10,50,50)];
ima.image= [UIImageimageNamed:@"5"];
ima.layer.masksToBounds=YES;
ima.layer.cornerRadius=25;
[celladdSubview: ima];
UILabel* lab = [[UILabelalloc]initWithFrame:CGRectMake(40,70,60,20)];
lab.text=@"全部任务";
lab.font= [UIFontsystemFontOfSize:10];
[celladdSubview:lab];
UIImageView* ima1 = [[UIImageViewalloc]initWithFrame:CGRectMake(140,10,50,50)];
ima1.image= [UIImageimageNamed:@"6"];
ima1.layer.masksToBounds=YES;
ima1.layer.cornerRadius=25;
[celladdSubview: ima1];
UILabel* lab1 = [[UILabelalloc]initWithFrame:CGRectMake(140,70,60,20)];
lab1.text=@"全部任务";
lab1.font= [UIFontsystemFontOfSize:10];
[celladdSubview:lab1];
UIImageView* ima2 = [[UIImageViewalloc]initWithFrame:CGRectMake(220,10,50,50)];
ima2.image= [UIImageimageNamed:@"7"];
ima2.layer.masksToBounds=YES;
ima2.layer.cornerRadius=25;
[celladdSubview: ima2];
UILabel* lab2 = [[UILabelalloc]initWithFrame:CGRectMake(220,70,60,20)];
lab2.text=@"全部任务";
lab2.font= [UIFontsystemFontOfSize:10];
[celladdSubview:lab2];
UIImageView* ima3 = [[UIImageViewalloc]initWithFrame:CGRectMake(300,10,50,50)];
ima3.image= [UIImageimageNamed:@"8"];
ima3.layer.masksToBounds=YES;
ima3.layer.cornerRadius=25;
[celladdSubview: ima3];
UILabel* lab3 = [[UILabelalloc]initWithFrame:CGRectMake(300,70,60,20)];
lab3.text=@"全部任务";
lab3.font= [UIFontsystemFontOfSize:10];
[celladdSubview:lab3];
}
}else{
tbv.rowHeight=300;
UIImageView* iam = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,300)];
iam.image = [UIImage imageNamed:@"屏幕快照 2018-11-15 上午10.16.48"];
[celladdSubview:iam];
}
returncell;
}
- (void)dian{
[self.navigationController pushViewController:[MapUIkit new] animated:YES];
}
/*
#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.
}
*/
// 滚动视图
- (void)scrollViewDidScroll:(UIScrollView*)scrollView{
// NSLog(@"%lf",scro.contentOffset.x);
pag.currentPage = scro.contentOffset.x/self.view.frame.size.width;
}
// 定时器
-(void)aaa{
[scro setContentOffset:CGPointMake(k * self.view.frame.size.width, 0)];
k++;
if(k>2){
k=0;
}
}
5.在第五个文件中写协议UITableViewDelegate和UITableViewDataSource
在协议中定义三个属性
UITableView * tbv;
NSArray* arr;
NSArray* imarr;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
tbv = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
tbv.dataSource = self;
tbv.delegate=self;
arr = @[@"我的包裹",@"我的包裹",@"我的包裹",@"我的包裹",@"我的包裹",@"我的包裹",@"我的包裹",@"我的包裹"];
imarr = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8"];
UIView* uiv = [[UIViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,200)];
uiv.backgroundColor = [UIColor orangeColor];
UIImageView * ima = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 100, 100)];
ima.image= [UIImageimageNamed:@"5"];
ima.layer.masksToBounds= YES;
ima.layer.cornerRadius = 50;
UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(180, 45, 100, 40)];
lab.text=@"12312312";
UIImageView* imag = [[UIImageViewalloc]initWithFrame:CGRectMake(0,150,self.view.frame.size.width,50)];
imag.image = [UIImage imageNamed:@"屏幕快照 2018-11-15 上午10.53.45"];
[uivaddSubview:imag];
[uivaddSubview:ima];
[uivaddSubview:lab];
tbv.tableHeaderView = uiv;
tbv.rowHeight = 40;
[self.view addSubview:tbv];
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
returnarr.count;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"2"];
if(!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"2"];
}
cell.imageView.image= [UIImageimageNamed:imarr[indexPath.row]];
cell.textLabel.text=arr[indexPath.row];
UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(350, 0, 40, 40)];
lab.text=@">";
lab.textColor= [UIColorlightGrayColor];
[celladdSubview:lab];
returncell;
}