#import <UIKit/UIKit.h>

#import "YQZMutableArray.h"

@interface YQZViewController : UIViewController

@property (nonatomic, strong) NSString *kTitle;

//保存当前正在运行的http请求

@property (nonatomic, strong) YQZMutableArray* httpRequestArray;

- (void)addBackBtnToHomePage;

- (void)addLeftBackBtn;

- (UIButton *)addRightTextButtonWithText:(NSString *)buttonText action:(SEL)action;

- (UIButton *)addRightImageButtonWithImageName:(NSString *)imageNamed action:(SEL)action;

- (UIButton *)addLeftTextButtonWithText:(NSString *)buttonText action:(SEL)action;

- (void)back;

- (void)backToHomepage;

- (void)addMakeCall;

- (void)loadTopData;

- (void)showLogin;

- (void)cancelHttpRequest;

@end

.m

#import "YQZViewController.h"

#import "YQZAppDelegate.h"

#import "YQZLoginViewController.h"

#import "SDWebImageManager.h"

#import "YQZImageCache.h"

#import "AFHttpClient.h"

@interface YQZViewController ()

@end

@implementation YQZViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self)

{

self.httpRequestArray = [[YQZMutableArray alloc] init];

}

return self;

}

- (void)viewDidLoad

{

[super viewDidLoad];

if (kdSystemVersion >= 7.0f) {

[self.navigationController.navigationBar setTranslucent:NO];

[self.navigationController.view setBackgroundColor:kYQZBorderGrayLightColor];

[self setExtendedLayoutIncludesOpaqueBars:YES];

[self setAutomaticallyAdjustsScrollViewInsets:YES];

[self setModalTransitionStyle:UIModalTransitionStyleCoverVertical];

[self setModalPresentationStyle:UIModalPresentationFullScreen];

[self setEdgesForExtendedLayout:UIRectEdgeAll];

self.edgesForExtendedLayout = UIRectEdgeNone;

}

//    if (kdSystemVersion < 7.0) {

//        self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,[UIFont boldSystemFontOfSize:20],UITextAttributeFont,[NSValue valueWithUIOffset:UIOffsetZero], UITextAttributeTextShadowOffset,nil];

//    } else if (kdSystemVersion >= 7.0)

//    {

//

//    }

}

- (void)dealloc

{

NSLog(@"%@ has dealloc",[NSString stringWithUTF8String:object_getClassName(self)]);

}

- (void)loadTopData

{

}

- (void)showLogin

{

if ([YQZLoginViewController canAutoLogin])

{

[self autoLogin];

} else {

[self manualLogin];

}

}

- (void)autoLogin

{

[YQZSetting sharedInstance].loginStatus = LoginStatusLogOut;

YQZLoginViewController *autoLoginViewController = [[YQZLoginViewController alloc] initWithNibName:@"YQZLoginViewController" bundle:nil];

[autoLoginViewController autoLogin];

}

- (void)manualLogin

{

YQZLoginViewController *loginViewController = [[YQZLoginViewController alloc] initWithNibName:@"YQZLoginViewController" bundle:nil];

loginViewController.delegate = self;

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:loginViewController];

//[self.navigationController presentViewController:navigationController animated:TRUE completion:NULL];

YQZAppDelegate* delegate = (YQZAppDelegate*)[UIApplication sharedApplication].delegate;

[delegate.window.rootViewController presentViewController:navigationController animated:YES completion:nil];

}

- (void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];

[[[SDWebImageManager sharedManager] imageCache] clearMemory];

[[YQZImageCache sharedInsance] clearCachedImages];

}

- (void)back

{

[self.view endEditing:YES];

[self cancelHttpRequest];

[self.navigationController popViewControllerAnimated:YES];

}

- (void)addMakeCall

{

UIButton *button =[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] ;

button.backgroundColor = [UIColor clearColor];

[button setImage:[UIImage imageNamed:@"打电话"] forState:UIControlStateNormal];

[button setImage:[UIImage imageNamed:@"打电话"] forState:UIControlStateHighlighted];

button.imageEdgeInsets = kNavigationRightButtonInSet;

[button addTarget:self action:@selector(makeCall) forControlEvents:UIControlEventTouchUpInside];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

}

- (void)makeCall

{

NSString *telStr = [NSString stringWithFormat:@"tel://%@", kCompanyPhone];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:telStr]];

[MobClick event:@"Other_CallTel"];

}

- (void)backToHomepage

{

[self.navigationController popViewControllerAnimated:YES];

}

- (void)addLeftBackBtn

{

UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]

initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace

target:nil action:nil];

if (kdSystemVersion >= 7.f) {

negativeSpacer.width = -10;

}

UIButton *button =[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] ;

button.backgroundColor = [UIColor clearColor];

[button setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];

[button setImage:[UIImage imageNamed:@"back_h"] forState:UIControlStateHighlighted];

[button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *backNavigationItem = [[UIBarButtonItem alloc] initWithCustomView:button];

self.navigationItem.leftBarButtonItems = @[negativeSpacer, backNavigationItem];

}

- (void)addBackBtnToHomePage

{

UIButton *button =[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)] ;

button.backgroundColor = [UIColor clearColor];

[button setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];

[button setImage:[UIImage imageNamed:@"back_h"] forState:UIControlStateHighlighted];

[button addTarget:self action:@selector(backToHomepage) forControlEvents:UIControlEventTouchUpInside];

self.navigationItem.leftBarButtonItem = nil;

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button] ;

}

- (UIButton *)addRightTextButtonWithText:(NSString *)buttonText action:(SEL)action

{

UIButton *textButton =[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 44)];

textButton.backgroundColor = [UIColor clearColor];

[textButton setTitle:buttonText forState:UIControlStateNormal];

textButton.titleLabel.font = [UIFont systemFontOfSize:kNavigationButtonFontSize];

if (buttonText.length == 4) {

if (kdSystemVersion >= 7.f) {

textButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -15);

}

}else {

if (kdSystemVersion >= 7.f) {

textButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -48);

}

}

[textButton addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:textButton];

return textButton;

}

- (UIButton *)addRightImageButtonWithImageName:(NSString *)imageName action:(SEL)action

{

UIButton *imageButton;

if (DEVICE_IS_IPHONE6Plus||DEVICE_IS_IPHONE6PlusBig) {

imageButton =[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];

}

else{

imageButton =[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];

}

imageButton.backgroundColor = [UIColor clearColor];

[imageButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];

[imageButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateHighlighted];

[imageButton setImageEdgeInsets:kNavigationRightButtonInSet];

imageButton.titleLabel.font = [UIFont systemFontOfSize:kNavigationButtonFontSize];

[imageButton addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:imageButton];

return imageButton;

}

- (UIButton *)addLeftTextButtonWithText:(NSString *)buttonText action:(SEL)action

{

UIButton *textButton =[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 44)];

textButton.backgroundColor = [UIColor clearColor];

[textButton setTitle:buttonText forState:UIControlStateNormal];

textButton.titleLabel.font = [UIFont systemFontOfSize:kNavigationButtonFontSize];

[textButton.titleLabel setTextAlignment:NSTextAlignmentLeft];

if (buttonText.length == 4) {

if (kdSystemVersion >= 7.f) {

textButton.titleEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 0);

}

}else {

if (kdSystemVersion >= 7.f) {

textButton.titleEdgeInsets = UIEdgeInsetsMake(0, -48, 0, 0);

}

}

[textButton addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];

self.navigationItem.leftBarButtonItem = nil;

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:textButton];

return textButton;

}

-(void)cancelHttpRequest

{

for (id opertion in self.httpRequestArray) {

if ([opertion isKindOfClass:[AFHTTPRequestOperation class]]) {

[opertion cancel];

}

}

[self.httpRequestArray removeAllObjects];

}

@end

最新文章

  1. 试用avalon2.0
  2. Azure SQL Data Warehouse
  3. Android接口传递Json数组的处理方式
  4. MVC下载文件方式
  5. webservice的简单示例的实现步骤
  6. BZOJ 2982 combination
  7. c++11编码规范 NULL还是nullptr
  8. 用GOACCESS分析NGINX日志
  9. flac文件提取专辑封面手记
  10. 手机装linux系统
  11. js中的true,false盲点
  12. ORACLE分区表、分区索引详解
  13. TPYBoard读取芯片上的温度传感器
  14. strace参数
  15. Flex读取txt文件里的内容(一)
  16. python S2-45 漏洞利用工具
  17. WebView与 JS 交互方式
  18. 3、class文件加载过程
  19. Log4j 基本配置示例
  20. OpenGL 用三角形模拟生成球面

热门文章

  1. matlab函数 bwperim
  2. Tomcat的安装及使用
  3. HTTP缓存控制
  4. caffe template
  5. PowerDesigner 导出 Excel
  6. (转)apache2.2.x+tomcat7.0.x集群+…
  7. ios之Block研究
  8. SQL Server(五)——常用函数 转
  9. android studio 改包名
  10. uoj#280. 【UTR #2】题目难度提升(构造)