#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self showAlert];
}
- (void)showAlert {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"2秒后将消失" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
[alert show];
[self performSelector:@selector(dimissAlert:) withObject:alert afterDelay:2.0];
}
- (void) dimissAlert:(UIAlertView *)alert {
if(alert){
[alert dismissWithClickedButtonIndex:[alert cancelButtonIndex] animated:YES];
}
}
@end
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad]
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self testAlert]
}
- (void)testAlert {
//添加要用到的Label
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(80, 280, 80, 40)]
label.backgroundColor = [UIColor orangeColor]
label.font = [UIFont systemFontOfSize:14]
label.text = @"提示信息"
[self.view addSubview:label]
//设置动画
CATransition * transion = [CATransition animation]
transion.type = @"push"
transion.subtype = @"fromRight"
[label.layer addAnimation:transion forKey:nil]
//不占用主线程
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
//这句话的意思是2秒后,把label移出视图
[label removeFromSuperview]
})
}
@end
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad]
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self testAlert]
}
- (void)testAlert {
//添加要用到的Label
UILabel * label = [[UILabel alloc] init]
[self.view addSubview:label]
label.backgroundColor = [UIColor orangeColor]
label.font = [UIFont systemFontOfSize:14]
label.textAlignment = NSTextAlignmentCenter
label.text = @"提示信息"
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(80);
make.height.mas_equalTo(40);
make.centerX.mas_equalTo(self.view.mas_centerX);
make.centerY.mas_equalTo(self.view.mas_centerY);
}]
//设置动画
CATransition * transion = [CATransition animation]
transion.type = @"push"
transion.subtype = @"fromRight"
[label.layer addAnimation:transion forKey:nil]
//不占用主线程
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.25 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
//这句话的意思是1.25秒后,把label移出视图
[label removeFromSuperview]
})
}
@end
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,WKNavigationDelegate>
@property (nonatomic, strong) UITableView *tableView
@property (nonatomic, strong) WKWebView *headerWebView
@end
@implementation ViewController
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation {
[webView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id _Nullable result,NSError *_Nullable error) {
//获取页面高度
CGFloat scrollHeight = [result doubleValue]
// self.headerWebView.height = scrollHeight
// self.headerWebView.scrollView.contentSize = CGSizeMake(kScreenWidth, scrollHeight)
self.headerWebView.frame = CGRectMake(0, 0, kScreenWidth, scrollHeight)
NSLog(@"scrollHeight 即为所求:%f",scrollHeight)
}]
}
- (WKWebView *)headerWebView {
if (_headerWebView == nil) {
NSString *jScript =@"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta); var imgs = document.getElementsByTagName('img');for (var i in imgs){imgs[i].style.maxWidth='100%';imgs[i].style.height='auto';}"
WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]
WKUserContentController *wkUController = [[WKUserContentController alloc] init]
[wkUController addUserScript:wkUScript]
WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init]
wkWebConfig.userContentController = wkUController
_headerWebView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:wkWebConfig]
_headerWebView.scrollView.scrollEnabled = NO
_headerWebView.navigationDelegate = self
NSString *str = @"<p><p>就在大家已经习惯锤子手机前CEO罗永浩每晚在交个朋友直播间卖力带货的时候,手机数码圈传来消息,原锤子手机团队组建的新石实验室被字节跳动并入教育硬件团队,不再进行手机研发业务。说直白点就是锤子手机团队垮了,去年十份推出的坚果R2 成为锤子手机的绝唱,锤子手机成为继诺基亚、金立之后又一消失的著名手机品牌。</p><p><img src='https://hhbusiness.oss-cn-shenzhen.aliyuncs.com/avatar/13FD9BAC-E053-C6D5-1E5B-9C32891C76F3.jpg' alt='编辑器图片'><br></p></p><p><br></p><p><b>锤子手机社会性死亡 手机市场垄断性发展趋势明显</b></p><p>对于锤子手机的消失,是有一些预兆的,去年10月22日才上市的坚果手机R2,最近搞了一波降价促销,原价4499元的手机直接降到了2999元,对于喜欢罗永浩的等等党来说,这自然是喜从天降,但对于之前刚刚买了R2的老粉来说,这简直是晴天霹雳,不少首批购买了坚果手机R2的罗粉纷纷跑到微博上吐槽,虽然软件产品经理朱海舟在晚间也发文向广大用户表示了道歉,但明眼人一看这锤子手机清仓跑路的架势太明显了。</p><p><img src='https://hhbusiness.oss-cn-shenzhen.aliyuncs.com/avatar/6DCB7E67-0909-9CAA-DF3D-B06353E69D85.jpg' alt='编辑器图片'><br></p><p>对于锤子手机来说,之所以在手机圈人气一直不低, 很大程度是因为罗永浩的网红效应,愿意为锤子手机买单的多半是老罗的粉丝,他们因为喜欢老罗这个人才爱屋及乌。现在锤子手机这样社会性死亡,广大罗粉肯定是有些遗憾的,虽然锤子手机有交互和OS系统方面的优点,但作为一个小众手机品牌,没有持续的供应链能力、资金链能力、研发链能力,其走上衰败也是自然而然的事情。</p><p><img src='https://hhbusiness.oss-cn-shenzhen.aliyuncs.com/avatar/D2CC55F8-2066-ACCB-41C9-0D97737AE6E1.jpg' alt='编辑器图片'><br></p><p><br></p><p>目前中国手机市场的整体是呈疲软状态的,几家主要手机品牌呈垄断性态势,华米OV(华为、小米、OPPO、vivo)的市场份额则从 78.3% 上升到 88.7%。</p><p>而2018 年到 2020 年第三季度,中小厂商占据的市场份额从12.5% 下降到了2.5%。在手机市场同质化严重、市场竞争越来越激烈的今天,像锤子这种家底不厚的的小众手机品牌被市场淘汰是自然而然的事情。</p><p><b>二手手机交易市场火爆 优品拍拍凭实力异军突起</b></p><p>一手手机市场的相对疲软,在一定程度上带火了二手手机销售市场。2020年,全球二手智能手机出货量达到2.254亿部,与2019年相比同比增长9.2%。在全球经济下行的大环境下,人们下意识会减少除衣食住行必需品之外的消费需求,二手手机作为比一手手机性价比更高的商品,越来越受到人们的青睐。</p><p>二手电子产品拍卖平台优品拍拍集合了国内顶级的二手手机产业链资源,作为一家自营平台,优品拍拍精选一手货源、质检严格,借助遍布海外60个多国家的销售网络,平台出售的手机价格全网最低,相比于其它平台,优品拍拍的货品价格透明,免收服务费,所有货源真机实拍,值得信赖。无论你是个人还是商户,在优品拍拍上都能找到适合自己的手机。</p><p><img src='https://hhbusiness.oss-cn-shenzhen.aliyuncs.com/avatar/B69858B9-6F8B-7725-2601-7CB777F821FC.png' alt='编辑器图片'><br></p><p>优品拍拍专注二手电子产品拍卖,关注我,一起淘好机、聊行业、学技巧~</p><div><br></div>"
[_headerWebView loadHTMLString:str baseURL:nil]
}
return _headerWebView
}
- (void)viewDidLoad {
[super viewDidLoad]
[self setupUI]
self.navigationItem.title = @"完美实现WKWebView动态高度"
}
- (void)setupUI {
[self.view addSubview:self.tableView]
self.tableView.tableHeaderView = self.headerWebView
// [self.view addSubview:self.headerWebView]
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCellID"]
cell.backgroundColor = [UIColor blackColor]
cell.textLabel.textColor = [UIColor whiteColor]
if (indexPath.row == 0) {
cell.textLabel.text = @"请注意header的博客内容是错误示范"
cell.textLabel.font = [UIFont systemFontOfSize:20 weight:1]
} else {
cell.textLabel.text = @"正确示范请查看footer"
cell.textLabel.font = [UIFont systemFontOfSize:30 weight:1]
}
return cell
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100
}
- (UITableView *)tableView {
if (_tableView == nil) {
_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, kSafeAreaTopHeight, kScreenWidth, kScreenHeight - kSafeAreaBottomHeight - kSafeAreaTopHeight) style:UITableViewStylePlain]
_tableView.delegate = self
_tableView.dataSource = self
_tableView.tableFooterView = [UIView new]
[_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCellID"]
}
return _tableView
}
@end