#import
#import
#import "RESideMenu.h" //抽屉视图第三方
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property(strong,nonatomic)RESideMenu *sideMenu;
@property (strong, nonatomic) UIWindow *window;
@property (readonly, strong) NSPersistentContainer *persistentContainer;
- (void)saveContext;
@end
#import "AppDelegate.h"
#import "LeftMenuViewController.h"
#import "QQQViewController.h"
#import "MapViewController.h"
#import "GuideViewController.h"
@interface AppDelegate ()
@property(nonatomic,strong)LeftMenuViewController *leftVC ;
@property(nonatomic,strong)UITabBarController *tabBarCtl;
@end
@implementation AppDelegate
-(UINavigationController *)creatNavigationWithController:(UIViewController *)vc title:(NSString *)title image:(NSString *)imgName selectImage:(NSString *)selImgName{
UINavigationController *nav =[[UINavigationController alloc]initWithRootViewController:vc] ;
vc.navigationItem.title = title ;
nav.tabBarItem = [[UITabBarItem alloc]initWithTitle:title image:[UIImage imageNamed:imgName] selectedImage:[UIImage imageNamed:selImgName]];
return nav;
}
-(LeftMenuViewController *)leftVC {
if (!_leftVC) {
_leftVC = [[LeftMenuViewController alloc]init];
}
return _leftVC ;
}
-(UITabBarController *)tabBarCtl {
if (!_tabBarCtl) {
_tabBarCtl = [[UITabBarController alloc]init] ;
UINavigationController *newsNav = [self creatNavigationWithController:[[MapViewController alloc]init] title:@"地图" image:@"TabBar_home_1@2x" selectImage:@"TabBar_home_2@2x"] ;
_tabBarCtl.viewControllers = @[newsNav];
}
return _tabBarCtl ;
}
-(RESideMenu *)sideMenu {
if (!_sideMenu) {
_sideMenu = [[RESideMenu alloc]initWithContentViewController:self.tabBarCtl leftMenuViewController:self.leftVC rightMenuViewController:nil] ;
_sideMenu.backgroundImage = [UIImage imageNamed:@"Stars@2x"];
_sideMenu.scaleContentView = NO ;
_sideMenu.contentViewInPortraitOffsetCenterX = FIT_X(100);
}
return _sideMenu ;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
GuideViewController *guideVC = [[GuideViewController alloc]init];
if ( ![[NSUserDefaults standardUserDefaults]objectForKey:NOT_FIRST_LANUCH]) {
self.window.rootViewController = guideVC ;
}
else {
NSString *savedVersion = [[NSUserDefaults standardUserDefaults]objectForKey:NOT_FIRST_LANUCH];
if ([savedVersion isEqualToString:VERSION_CURRENT]) {
self.window.rootViewController = self.sideMenu;
}
else{
self.window.rootViewController = guideVC ;
}
}
return YES;
}
#ifndef Stary_pch
#define Stary_pch
#import "BaseViewController.h"
#define SCREEN_W [UIScreen mainScreen].bounds.size.width
#define SCREEN_H [UIScreen mainScreen].bounds.size.height
#define FIT_X(w) (SCREEN_W / 375. * (w))
#define FIT_Y(h) (SCREEN_H / 667. * (h))
#define VERSION_CURRENT [[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleShortVersionString"]
#define NOT_FIRST_LANUCH @"NotFirstLanuch"
#define App_Delegate (AppDelegate *)[UIApplication sharedApplication].delegate
#endif
#import "GuideViewController.h"
#import "ImageScrollView.h"
#import "AppDelegate.h"
@interface GuideViewController ()<ImageScrollViewDelegate>
@end
@implementation GuideViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *imgArr = @[@"guidePage1.png",@"guidePage2.png",@"guidePage3.png"] ;
ImageScrollView *imgScrView = [[ImageScrollView alloc]initWithFrame:self.view.frame style:ImageScrollType_Guide images:imgArr confirmBtnTitle:@"立即体验" confirmBtnTitleColor:[UIColor whiteColor] confirmBtnFrame:CGRectMake(FIT_X(260), FIT_Y(30), FIT_X(120), FIT_Y(40)) autoScrollTimeInterval:0.0 delegate: self ];
[self.view addSubview:imgScrView] ;
[imgScrView addPageControlToSuperView:self.view] ;
}
#pragma -mark 实现协议imageScrollViewDelegate
-(void)experienceDidHandle {
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults] ;
[ud setObject:VERSION_CURRENT forKey:NOT_FIRST_LANUCH] ;
[ud synchronize] ;
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate ;
appDelegate.window.rootViewController = appDelegate.sideMenu;
}
#import "BaseViewController.h"
#import "AppDelegate.h"
@interface BaseViewController ()
@end
@implementation BaseViewController
- (void)viewDidLoad {
[super viewDidLoad];
if (self.navigationController.viewControllers.count == 1) {
UIButton *headBtn = [UIButton buttonWithType:UIButtonTypeCustom];
headBtn.frame = CGRectMake(0, 0, 40, 40) ;
headBtn.clipsToBounds = YES ;
headBtn.layer.cornerRadius = 40 / 2 ;
[headBtn setImage:[UIImage imageNamed:@"40"] forState:UIControlStateNormal];
[headBtn addTarget:self action:@selector(headBtnHandle:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:headBtn];
}
else {
self.navigationItem.hidesBackButton = YES ;
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
backBtn.frame = CGRectMake(0, 0, 15, 10);
[backBtn setImage:[UIImage imageNamed:@"navigationItem_back"] forState:UIControlStateNormal] ;
[backBtn addTarget:self action:@selector(backBtnHandle:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem =[[UIBarButtonItem alloc]initWithCustomView:backBtn] ;
}
}
#pragma mark -------触发方法 ----------
-(void)headBtnHandle:(id)sender{
AppDelegate *appDele = App_Delegate ;
[appDele.sideMenu presentLeftMenuViewController];
}
-(void)backBtnHandle:(id)sender{
[self.navigationController popViewControllerAnimated:YES] ;
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated] ;
if (self.navigationController.viewControllers.count == 1) {
self.tabBarController.tabBar.hidden = NO ;
}
else {
self.navigationController.tabBarController.tabBar.hidden = YES ;
}
}
#import "LeftMenuViewController.h"
@interface LeftMenuViewController ()<UITableViewDelegate,UITableViewDataSource>{
NSArray *_tableDatas ;
}
@property(nonatomic,strong)UIImageView *headImgView ;
@property(nonatomic,strong)UITableView *table ;
@end
@implementation LeftMenuViewController
#pragma mark ----------控件实例化-----------------
-(UIImageView *)headImgView {
if (!_headImgView) {
_headImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, FIT_X(80), FIT_Y(80))] ;
_headImgView.center = CGPointMake(SCREEN_W/4+FIT_X(50), FIT_Y(104)) ;
_headImgView.clipsToBounds = YES ;
_headImgView.layer.cornerRadius = FIT_X(40) ;
_headImgView.image = [UIImage imageNamed:@"40"] ;
_headImgView.userInteractionEnabled = YES ;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headImgDidHandle:)];
[_headImgView addGestureRecognizer:tap] ;
}
return _headImgView ;
}
-(UITableView *)table {
if (!_table) {
_table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, FIT_X(300), 200) style:UITableViewStylePlain] ;
_table.rowHeight = 50;
_table.center = CGPointMake(self.headImgView.center.x, self.headImgView.center.y+self.headImgView.frame.size.height/2+100+FIT_Y(20)) ;
_table.scrollEnabled = NO ;
_table.backgroundColor = [UIColor clearColor];
_table.dataSource = self ;
_table.delegate = self;
}
return _table ;
}
#pragma mark ----------UITableViewDelegate,UITableViewDataSource-----------------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _tableDatas.count ;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] ;
}
cell.textLabel.text = _tableDatas[indexPath.row] ;
cell.backgroundColor = [UIColor clearColor] ;
cell.textLabel.textColor = [UIColor whiteColor] ;
cell.textLabel.font =[UIFont systemFontOfSize:18];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell ;
}
#pragma mark ----------触发事件-----------------
-(void)headImgDidHandle:(id)sender{
NSLog(@"点击了按钮");
}
#pragma mark -------loadView ------
-(void)loadView {
[super loadView] ;
[self.view addSubview:self.headImgView];
[self.view addSubview:self.table] ;
}
- (void)viewDidLoad {
[super viewDidLoad];
_tableDatas = @[@"我的钱包",@"我的卡卷",@"我的行程",@"邀请行程",@"你的",@"啦啦啦啦",@"我的旅途"] ;
[self.table reloadData] ;
}
#import "QQQViewController.h"
@interface QQQViewController ()
@end
@implementation QQQViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor yellowColor] ;
}
MapViewController.m
#import "MapViewController.h"
#import "QQQViewController.h"
#import //地图
#import //定位
@interface MapViewController ()<MKMapViewDelegate>
@property (strong, nonatomic) IBOutlet MKMapView *mapView;
@property (strong,nonatomic)CLGeocoder *geocoder;
- (IBAction)button:(id)sender;
@end
@implementation MapViewController
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHandle:)] ;
[self.view addGestureRecognizer:tap];
_geocoder = [[CLGeocoder alloc]init];
self.mapView.mapType = MKMapTypeStandard;
self.mapView.zoomEnabled =YES;
self.mapView.scrollEnabled =YES;
self.mapView.rotateEnabled =YES;
self.mapView.showsUserLocation = YES;
[self locateToLatitude:37.23 longitude:122.1234];
UILongPressGestureRecognizer* gesture = [[UILongPressGestureRecognizer
alloc]initWithTarget:self action:@selector(longPress:)];
[self.view addGestureRecognizer:gesture];
self.mapView.delegate =self;
}
#pragma mark --手势回调
- (void) longPress:(UILongPressGestureRecognizer*)gesture{
CGPoint pos = [gesture locationInView:self.mapView];
CLLocationCoordinate2D coord = [self.mapView convertPoint:pos
toCoordinateFromView:self.mapView];
CLLocation* location = [[CLLocation alloc]initWithLatitude:coord.latitude
longitude:coord.longitude];
[_geocoder reverseGeocodeLocation:location completionHandler:
^(NSArray *placemarks,NSError *error)
{
if (placemarks.count >0 && error ==nil)
{
CLPlacemark* placemark = [placemarks objectAtIndex:0];
NSArray* addrArray = placemark
.addressDictionary[@"FormattedAddressLines"];
NSMutableString* address = [[NSMutableString alloc]init];
for(int i =0 ; i < addrArray.count ; i ++)
{
[address appendString:addrArray[i]];
}
MKPointAnnotation *annotation = [[MKPointAnnotation alloc]init];
annotation.title = placemark.name;
annotation.subtitle = address;
annotation.coordinate = coord;
[self.mapView addAnnotation:annotation];
}
}];
}
#pragma mark --自定义封装定位方法
- (void)locateToLatitude:(CGFloat)latitude longitude:(CGFloat)longitude{
CLLocationCoordinate2D center = {latitude , longitude};
MKCoordinateSpan span;
span.latitudeDelta =0.01;
span.longitudeDelta =0.01;
MKCoordinateRegion region = {center,span};
[self.mapView setRegion:region animated:YES];
MKPointAnnotation* annotation = [[MKPointAnnotation alloc]init];
annotation.title =@"北京石羿科技发展有限公司";
annotation.subtitle =@"海淀区中关村软件园";
CLLocationCoordinate2D coordinate = {latitude , longitude};
annotation.coordinate = coordinate;
[self.mapView addAnnotation:annotation];
}
#pragma mark -自定义锚点
- (MKAnnotationView *) mapView:(MKMapView *)mapView
viewForAnnotation:(id ) annotation{
static NSString* annoId =@"fkAnno";
MKAnnotationView* annoView = [mapView
dequeueReusableAnnotationViewWithIdentifier:annoId];
if (!annoView)
{
annoView= [[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annoId];
}
annoView.image = [UIImage imageNamed:@"pos.gif"];
annoView.canShowCallout =YES;
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[button addTarget:self action:@selector(buttonTapped:)
forControlEvents:UIControlEventTouchUpInside];
annoView.rightCalloutAccessoryView = button;
return annoView;
}
#pragma mark -自定义锚点 --里面的详情按钮
- (void) buttonTapped:(id)sender
{
NSLog(@"您点击了锚点信息!");
}
-(void)tapHandle:(id)sender{
QQQViewController *detailVC =[[ QQQViewController alloc]init];
[self.navigationController pushViewController:detailVC animated:YES] ;
}
![本图片表示map的xib文件](http: