首页 > 代码库 > ios 小知识

ios 小知识

键盘事件监听   UIKeyboardWillShowNotification 

[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(keyboardWillShown:)name:UIKeyboardWillShowNotificationobject:nil];

keyboardWillShown 方法中 

NSValue *value = http://www.mamicode.com/[info objectForKey:UIKeyboardFrameEndUserInfoKey];

[value CGRectValue].size; 键盘大小


网页是否包含视频

NSString * hasVideoTestString = @"document.documentElement.getElementsByTagName(\"video\").length";
        NSString * result = [self stringByEvaluatingJavaScriptFromString:hasVideoTestString];
        hasVideoTag = [result integerValue] >= 1? YES : NO;

播放视频  letv 1905 土豆 优酷      ok 其他没测试

@"document.documentElement.getElementsByTagName(\"video\")[0].play()"

//为了捕获到滚动事件   获取<span style="font-family: Arial, Helvetica, sans-serif;">webView的滚动事件</span>    NSArray* arr = [self.webView subviews];
    UIScrollView* sView = [arr objectAtIndex:0];
    [sView setOpaque:NO];
    sView.delegate = self;


//更改 最顶上的时间的样式
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];

//停止web加载  部分网页会加载失败    会屏蔽掉部分一直在后台运行的js

[webView stopLoading];



ios 小知识