// // BaseVIewContorller.m // Ifish // // Created by imac on 15/9/28. // Copyright © 2015年 imac. All rights reserved. // #import "BaseVIewContorller.h" #import "AppDelegate.h" #import "UINavigationBar+Background.h" @interface BaseVIewContorller () @end @implementation BaseVIewContorller - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self initNav]; self.view.backgroundColor = TABLE_BACKGROUD_COLOR; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController.navigationBar resetBackgroundImage]; } -(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; } - (void)addTitleViewWithTitle:(NSString *)title{ UILabel*labe=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 44)]; labe.text=title; labe.textAlignment=NSTextAlignmentCenter; labe.textColor=[UIColor whiteColor]; labe.font = [UIFont systemFontOfSize:19]; self.navigationItem.titleView=labe; } -(void)initNav{ // 1. 可以改变全栈back按钮 图片 60*60 @2x像素 // UIImage *backImage = [UIImage imageNamed:@"leftItem"]; // [[UIBarButtonItem appearance] setBackButtonBackgroundImage:[backImage resizableImageWithCapInsets:UIEdgeInsetsMake(0,0,0,0)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; // [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0,-60) forBarMetrics:UIBarMetricsDefault];// UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init]; // backItem.title=@""; // backItem.image=[UIImage imageNamed:@"leftItem"]; // self.navigationItem.backBarButtonItem=backItem; _bakbutton = [UIButton buttonWithType:UIButtonTypeCustom]; _bakbutton.frame = CGRectMake(0,0,48,44); [_bakbutton setImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal]; _bakbutton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [_bakbutton addTarget: self action: @selector(goBackAction) forControlEvents: UIControlEventTouchUpInside]; [_bakbutton setContentEdgeInsets:UIEdgeInsetsMake(0, 10, 0, -10)]; _back=[[UIBarButtonItem alloc] initWithCustomView:_bakbutton]; self.navigationItem.leftBarButtonItem=_back; } -(void)goBackAction{ [self.navigationController popViewControllerAnimated:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } -(void)showTitle:(NSString*)title messsage:(NSString*)message{ UIAlertView *alert=[[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil]; NSTimeInterval dismissSeconds=1.0; [alert show]; [self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:dismissSeconds]; // UIAlertController *alertContorller=[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; // UIAlertAction*cancleAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]; // // UIAlertAction *sureAction=[UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:nil]; // [alertContorller addAction:cancleAction]; // [alertContorller addAction:sureAction]; // [self presentViewController:alertContorller animated:YES completion:nil]; } -(void)dismissAlert:(UIAlertView*)alertView{ [alertView dismissWithClickedButtonIndex:[alertView cancelButtonIndex] animated:YES]; } -(void)creatMyindicaterView{ // _indicatorView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; // // _indicatorView.center=CGPointMake(kScreenSize.width/2, kScreenSize.height/2+100); // //[_indicatorView startAnimating]; // _indicatorView.frame=CGRectMake(kScreenSize.width/2-20,kScreenSize.height/2-20,40, 40); // // _indicatorView.backgroundColor=[UIColor lightGrayColor]; // [self.view addSubview:_indicatorView]; } #pragma mark - 竖屏时,显示状态栏 -(BOOL)prefersStatusBarHidden{ return NO; } //白色状态栏 - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } #pragma mark - 屏幕Autorotate -(BOOL)shouldAutorotate{ return YES; } #pragma mark 屏幕支持的旋转方向 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface { return (interface == UIInterfaceOrientationPortrait || interface == UIInterfaceOrientationLandscapeRight); } // #ifdef IOS6 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; } - (BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeRight; } #endif // #pragma mark 支持哪些方向 -(UIInterfaceOrientationMask)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeRight; } #pragma mark 一开始希望的屏幕方向 -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ return UIInterfaceOrientationPortrait; } #pragma mark - 屏幕旋转 -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (toInterfaceOrientation == UIInterfaceOrientationPortrait) { } else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) { } else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { } } @end