//
|
// WebControllerView.m
|
// BuWanVideo2.0
|
//
|
// Created by weikou2016 on 16/8/17.
|
// Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
|
//
|
|
#import "WebControllerView.h"
|
#import <WebKit/WebKit.h>
|
|
@interface WebControllerView () <WKUIDelegate, WKNavigationDelegate> {
|
WKWebView * webview;
|
UIButton *button2;
|
CABasicAnimation *animation;
|
}
|
|
@end
|
|
@implementation WebControllerView
|
@synthesize url;
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
[self initScene];
|
}
|
|
-(void)initScene {
|
|
self.navigationItem.title = @"发现";
|
self.view.backgroundColor=[UIColor whiteColor];
|
|
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:18]};
|
|
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; //返回上个网页
|
[button setImage:[[UIImage imageNamed:@"详情页面返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
|
[button addTarget:self action:@selector(back)
|
forControlEvents:UIControlEventTouchUpInside];
|
button.frame = CGRectMake(0, 0, 32, 32);
|
UIBarButtonItem *iconBarItem=[[UIBarButtonItem alloc] initWithCustomView:button];
|
self.navigationItem.leftBarButtonItem = iconBarItem;
|
|
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom]; //退出页面
|
[button1 setTitle:@"关闭" forState:UIControlStateNormal];
|
[button1 addTarget:self action:@selector(webback) forControlEvents:UIControlEventTouchUpInside];
|
button1.frame = CGRectMake(100, 32, 30, 18);
|
button1.titleLabel.font = [UIFont systemFontOfSize:14];
|
[button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
UIBarButtonItem *bar1 = [[UIBarButtonItem alloc]initWithCustomView:button1];
|
UIBarButtonItem *bar2 = self.navigationItem.leftBarButtonItem;
|
NSArray *arr = @[bar2,bar1];
|
self.navigationItem.leftBarButtonItems = arr;
|
|
button2 = [UIButton buttonWithType:UIButtonTypeCustom]; //退出页面
|
[button2 setImage:[[UIImage imageNamed:@"网页刷新"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
|
[button2 addTarget:self action:@selector(refurbish) forControlEvents:UIControlEventTouchUpInside];
|
button2.frame = CGRectMake(100, 32, 32, 32);
|
UIBarButtonItem *bar3 = [[UIBarButtonItem alloc]initWithCustomView:button2];
|
self.navigationItem.rightBarButtonItem = bar3;
|
|
webview = [[WKWebView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height)];
|
webview.UIDelegate = self;
|
webview.navigationDelegate = self;
|
|
[self.view addSubview:webview];
|
|
NSURLRequest *request = [NSURLRequest requestWithURL:url];
|
[webview loadRequest:request];
|
|
[self beginrotate];
|
}
|
|
-(void)webback{
|
[self.navigationController popViewControllerAnimated:YES];
|
}
|
|
-(void)back{
|
if([webview canGoBack]){
|
[webview goBack];
|
}else{
|
[self.navigationController popViewControllerAnimated:YES];
|
}
|
}
|
|
-(void)refurbish {
|
[webview reload];
|
}
|
|
//9.0才能使用,web内容处理中断时会触发
|
- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
|
[webView reload];
|
}
|
|
// 页面开始加载时调用
|
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
|
if(!animation){
|
[self beginrotate];
|
}
|
}
|
|
// 页面加载失败时调用
|
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
|
}
|
|
// 页面加载完成之后调用
|
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
|
[self stoprotate];
|
}
|
|
-(void)beginrotate{
|
animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
|
animation.toValue = [NSNumber numberWithFloat:-M_PI*2.0];
|
animation.duration = 1;
|
animation.cumulative = YES;
|
animation.repeatCount = MAXFLOAT;
|
[button2.layer addAnimation:animation forKey:@"rotationAnimation"];
|
}
|
|
- (void)stoprotate {
|
[button2.layer removeAllAnimations];
|
animation = nil;
|
}
|
@end
|