add 添加原生标题栏
This commit is contained in:
parent
031d07d47b
commit
7fa4336a77
@ -22,6 +22,10 @@
|
|||||||
|
|
||||||
@property (nonatomic, assign) BOOL location;
|
@property (nonatomic, assign) BOOL location;
|
||||||
@property (nonatomic, assign) BOOL statusbar;
|
@property (nonatomic, assign) BOOL statusbar;
|
||||||
|
@property (nonatomic, assign) BOOL titlebar;
|
||||||
|
@property (nonatomic, copy) NSString* color;
|
||||||
|
@property (nonatomic, copy) NSString* background;
|
||||||
|
@property (nonatomic, assign) BOOL backbutton;
|
||||||
@property (nonatomic, assign) BOOL toolbar;
|
@property (nonatomic, assign) BOOL toolbar;
|
||||||
@property (nonatomic, copy) NSString* closebuttoncaption;
|
@property (nonatomic, copy) NSString* closebuttoncaption;
|
||||||
@property (nonatomic, copy) NSString* closebuttoncolor;
|
@property (nonatomic, copy) NSString* closebuttoncolor;
|
||||||
|
@ -27,7 +27,9 @@
|
|||||||
// default values
|
// default values
|
||||||
self.location = YES;
|
self.location = YES;
|
||||||
self.toolbar = YES;
|
self.toolbar = YES;
|
||||||
self.statusbar = YES;
|
self.titlebar = NO;
|
||||||
|
self.color = nil;
|
||||||
|
self.background = nil;
|
||||||
self.closebuttoncaption = nil;
|
self.closebuttoncaption = nil;
|
||||||
self.toolbarposition = @"bottom";
|
self.toolbarposition = @"bottom";
|
||||||
self.cleardata = NO;
|
self.cleardata = NO;
|
||||||
|
@ -70,6 +70,7 @@
|
|||||||
@property (nonatomic, strong) IBOutlet UIBarButtonItem* forwardButton;
|
@property (nonatomic, strong) IBOutlet UIBarButtonItem* forwardButton;
|
||||||
@property (nonatomic, strong) IBOutlet UIActivityIndicatorView* spinner;
|
@property (nonatomic, strong) IBOutlet UIActivityIndicatorView* spinner;
|
||||||
@property (nonatomic, strong) IBOutlet UIToolbar* toolbar;
|
@property (nonatomic, strong) IBOutlet UIToolbar* toolbar;
|
||||||
|
@property (nonatomic, strong) IBOutlet UINavigationBar*titlebar;
|
||||||
@property (nonatomic, strong) IBOutlet CDVWKInAppBrowserUIDelegate* webViewUIDelegate;
|
@property (nonatomic, strong) IBOutlet CDVWKInAppBrowserUIDelegate* webViewUIDelegate;
|
||||||
|
|
||||||
@property (nonatomic, weak) id <CDVScreenOrientationDelegate> orientationDelegate;
|
@property (nonatomic, weak) id <CDVScreenOrientationDelegate> orientationDelegate;
|
||||||
|
@ -309,26 +309,10 @@ static CDVWKInAppBrowser* instance = nil;
|
|||||||
// Run later to avoid the "took a long time" log message.
|
// Run later to avoid the "took a long time" log message.
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
if (weakSelf.inAppBrowserViewController != nil) {
|
if (weakSelf.inAppBrowserViewController != nil) {
|
||||||
// float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
|
/* 开始处理遮挡相机插件问题*/
|
||||||
// __strong __typeof(weakSelf) strongSelf = weakSelf;
|
self.inAppBrowserViewController.view.frame = CGRectMake(0,self.statusbarHieght,self.inAppBrowserViewController.view.frame.size.width,self.inAppBrowserViewController.view.frame.size.height - self.statusbarHieght/2);
|
||||||
// if (!strongSelf->tmpWindow) {
|
|
||||||
// CGRect frame = [[UIScreen mainScreen] bounds];
|
|
||||||
// if(initHidden && osVersion < 11){
|
|
||||||
// frame.origin.x = -10000;
|
|
||||||
// }
|
|
||||||
// strongSelf->tmpWindow = [[UIWindow alloc] initWithFrame:frame];
|
|
||||||
// }
|
|
||||||
// UIViewController *tmpController = [[UIViewController alloc] init];
|
|
||||||
//
|
|
||||||
// [strongSelf->tmpWindow setRootViewController:tmpController];
|
|
||||||
// [strongSelf->tmpWindow setWindowLevel:UIWindowLevelNormal];
|
|
||||||
//
|
|
||||||
// if(!initHidden || osVersion < 11){
|
|
||||||
// [self->tmpWindow makeKeyAndVisible];
|
|
||||||
// }
|
|
||||||
// [tmpController presentViewController:nav animated:!noAnimate completion:nil];
|
|
||||||
self.inAppBrowserViewController.view.frame = CGRectMake(0,self.statusbarHieght,self.inAppBrowserViewController.view.frame.size.width,self.inAppBrowserViewController.view.frame.size.height - 10);
|
|
||||||
[self.viewController.view addSubview:self.inAppBrowserViewController.view];
|
[self.viewController.view addSubview:self.inAppBrowserViewController.view];
|
||||||
|
/* 结束处理遮挡相机插件问题*/
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -918,6 +902,53 @@ BOOL isExiting = FALSE;
|
|||||||
} else {
|
} else {
|
||||||
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]];
|
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]];
|
||||||
}
|
}
|
||||||
|
// 开始添加标题栏
|
||||||
|
self.titlebar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
|
||||||
|
UIColor *backgroundColor = nil;
|
||||||
|
if(_browserOptions.background == nil) {
|
||||||
|
backgroundColor = [UIColor whiteColor];
|
||||||
|
}else{
|
||||||
|
backgroundColor = [self colorFromHexString:_browserOptions.background];
|
||||||
|
}
|
||||||
|
UIColor *fontColor = nil;
|
||||||
|
if(_browserOptions.color == nil) {
|
||||||
|
fontColor = [UIColor blackColor];
|
||||||
|
}else{
|
||||||
|
fontColor = [self colorFromHexString:_browserOptions.color];
|
||||||
|
}
|
||||||
|
|
||||||
|
self.titlebar.barTintColor = backgroundColor;
|
||||||
|
self.titlebar.tintColor =fontColor;
|
||||||
|
self.titlebar.translucent = YES;
|
||||||
|
UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:nil];
|
||||||
|
NSDictionary *barButtonAppearanceDict = @{NSFontAttributeName : [UIFont fontWithName:@"Symbol" size:24], NSForegroundColorAttributeName: fontColor};
|
||||||
|
if(_browserOptions.backbutton) {
|
||||||
|
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle: @"❮"
|
||||||
|
style:UIBarButtonItemStylePlain
|
||||||
|
target:self
|
||||||
|
action:@selector(goBack:)];
|
||||||
|
leftButton.tintColor = fontColor;
|
||||||
|
[leftButton setTitleTextAttributes:barButtonAppearanceDict forState:UIControlStateNormal];
|
||||||
|
[navigationItem setLeftBarButtonItem:leftButton];
|
||||||
|
}
|
||||||
|
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"⊗"
|
||||||
|
style:UIBarButtonItemStyleDone
|
||||||
|
target:self
|
||||||
|
action:@selector(close)];
|
||||||
|
[rightButton setTitleTextAttributes:barButtonAppearanceDict forState:UIControlStateNormal];
|
||||||
|
rightButton.tintColor = fontColor;
|
||||||
|
//设置导航栏内容
|
||||||
|
[navigationItem setTitle:self.webView.title];
|
||||||
|
//把导航栏集合添加入导航栏中,设置动画关闭
|
||||||
|
[self.titlebar pushNavigationItem:navigationItem animated:NO];
|
||||||
|
|
||||||
|
//把左右两个按钮添加入导航栏集合中
|
||||||
|
[navigationItem setRightBarButtonItem:rightButton];
|
||||||
|
self.titlebar.hidden = !_browserOptions.titlebar;
|
||||||
|
|
||||||
|
[self.view addSubview:self.titlebar];
|
||||||
|
|
||||||
|
// 结束添加标题栏
|
||||||
|
|
||||||
self.view.backgroundColor = [UIColor grayColor];
|
self.view.backgroundColor = [UIColor grayColor];
|
||||||
[self.view addSubview:self.toolbar];
|
[self.view addSubview:self.toolbar];
|
||||||
@ -1098,9 +1129,6 @@ BOOL isExiting = FALSE;
|
|||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)newClose{
|
|
||||||
|
|
||||||
}
|
|
||||||
- (void)close
|
- (void)close
|
||||||
{
|
{
|
||||||
self.currentURL = nil;
|
self.currentURL = nil;
|
||||||
@ -1132,7 +1160,11 @@ BOOL isExiting = FALSE;
|
|||||||
|
|
||||||
- (void)goBack:(id)sender
|
- (void)goBack:(id)sender
|
||||||
{
|
{
|
||||||
|
if(self.webView.canGoBack){
|
||||||
[self.webView goBack];
|
[self.webView goBack];
|
||||||
|
} else {
|
||||||
|
[self close];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)goForward:(id)sender
|
- (void)goForward:(id)sender
|
||||||
@ -1145,8 +1177,9 @@ BOOL isExiting = FALSE;
|
|||||||
if (IsAtLeastiOSVersion(@"7.0") && !viewRenderedAtLeastOnce) {
|
if (IsAtLeastiOSVersion(@"7.0") && !viewRenderedAtLeastOnce) {
|
||||||
viewRenderedAtLeastOnce = TRUE;
|
viewRenderedAtLeastOnce = TRUE;
|
||||||
CGRect viewBounds = [self.webView bounds];
|
CGRect viewBounds = [self.webView bounds];
|
||||||
viewBounds.origin.y = self.statusbarHieght;
|
int offsetY = _browserOptions.titlebar? 44 : 0 ;
|
||||||
viewBounds.size.height = viewBounds.size.height - self.statusbarHieght;
|
viewBounds.origin.y = offsetY ;
|
||||||
|
viewBounds.size.height = viewBounds.size.height - offsetY;
|
||||||
self.webView.frame = viewBounds;
|
self.webView.frame = viewBounds;
|
||||||
[[UIApplication sharedApplication] setStatusBarStyle:[self preferredStatusBarStyle]];
|
[[UIApplication sharedApplication] setStatusBarStyle:[self preferredStatusBarStyle]];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user