iOS 学习 --- OC与JS交互(UIWebView)

UIWebView的属性

//代理属性
@property (nullable, nonatomic, assign) id  delegate;
//WebView内部的scrollView,只读,可以通过这个属性设置scrollView的代理,就可以控制整个WebView的滚动事件
@property (nonatomic, readonly, strong) UIScrollView *scrollView NS_AVAILABLE_IOS(5_0);

  NSURLRequest介绍

//WebView的请求,这个属性一般在整个加载完成后才能拿到??????
@property (nullable, nonatomic, readonly, strong) NSURLRequest *request;
//YES:允许后退????
@property (nonatomic, readonly, getter=canGoBack) BOOL canGoBack;
//YES:允许前进????
@property (nonatomic, readonly, getter=canGoForward) BOOL canGoForward;
//YES:说明WebView还在加载数据,所有数据加载完毕后,loading就会为NO????
@property (nonatomic, readonly, getter=isLoading) BOOL loading;
//????
@property (nonatomic) BOOL detectsPhoneNumbers NS_DEPRECATED_IOS(2_0, 3_0);
//设置某些数据变为链接形式,这个枚举类型可以设置如电话号,地址,邮箱等转化为链接
@property (nonatomic) UIDataDetectorTypes dataDetectorTypes NS_AVAILABLE_IOS(3_0);
//设置为否使用内联播放器播放视频
@property (nonatomic) BOOL allowsInlineMediaPlayback NS_AVAILABLE_IOS(4_0); // iPhone Safari defaults to NO. iPad Safari defaults to YES
//设置视频是否自动播放
@property (nonatomic) BOOL mediaPlaybackRequiresUserAction NS_AVAILABLE_IOS(4_0); // iPhone and iPad Safari both default to YES
//设置音频播放是否支持AriPlay功能???
@property (nonatomic) BOOL mediaPlaybackAllowsAirPlay NS_AVAILABLE_IOS(5_0); // iPhone and iPad Safari both default to YES
//设置是否将数据加载入内存后渲染界面
@property (nonatomic) BOOL suppressesIncrementalRendering NS_AVAILABLE_IOS(6_0); // iPhone and iPad Safari both default to NO
//设置用户是否能打开keyboard交互
@property (nonatomic) BOOL keyboardDisplayRequiresUserAction NS_AVAILABLE_IOS(6_0); // default is YES
//iOS7新特性
//枚举类型,当网页的大小超出view时,将网页以翻页的效果展示
@property (nonatomic) UIWebPaginationMode paginationMode NS_AVAILABLE_IOS(7_0);

typedef NS_ENUM(NSInteger, UIWebPaginationMode) {
    UIWebPaginationModeUnpaginated,//不使用翻页效果
    UIWebPaginationModeLeftToRight,//从左向右翻页
    UIWebPaginationModeTopToBottom,//从上向下翻页
    UIWebPaginationModeBottomToTop,//从下向上翻页
    UIWebPaginationModeRightToLeft//从右向左翻页
} __TVOS_PROHIBITED;

//这个属性决定CSS的属性分页是可用还是忽略。默认是UIWebPaginationBreakingModePage????
@property (nonatomic) UIWebPaginationBreakingMode paginationBreakingMode NS_AVAILABLE_IOS(7_0);
//设置每一页的长度
@property (nonatomic) CGFloat pageLength NS_AVAILABLE_IOS(7_0);
//设置每一页的间距
@property (nonatomic) CGFloat gapBetweenPages NS_AVAILABLE_IOS(7_0);
//获取页数
@property (nonatomic, readonly) NSUInteger pageCount NS_AVAILABLE_IOS(7_0);
//iOS9新增
@property (nonatomic) BOOL allowsPictureInPictureMediaPlayback NS_AVAILABLE_IOS(9_0);

@property (nonatomic) BOOL allowsLinkPreview NS_AVAILABLE_IOS(9_0); // default is NO

 

UIWebView的代理方法

/**
   JS交互时的重点方法
   UIWebView的代理方法,当webview开始加载请求的时候回去调用,可以拦截一些用户的行为是否加载。返回YES代表允许加载,返回NO代表停止加载。
 */
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
/**
   webView加载开始的时候调用
 */
- (void)webViewDidStartLoad:(UIWebView *)webView;
/**
  webView加载完毕的时候调用。
 */
- (void)webViewDidFinishLoad:(UIWebView *)webView;
/**
   webView加载失败的时候调用
 */
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;

UIWebView的对象方法

//加载一个请求(常用)
- (void)loadRequest:(NSURLRequest *)request;
//加载本地HTML(常用)
- (void)loadHTMLString:(NSString *)string baseURL:(nullable NSURL *)baseURL;
//加载Data数据
- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL;

//刷新网页
- (void)reload;
//停止网页加载内容
- (void)stopLoading;
//后退
- (void)goBack;
//前进
- (void)goForward;
//执行JS方法
- (nullable NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script;

相关文章

iOS-NSURLRequest

NSURLRequest和NSMutableURLRequest

你可能感兴趣的:(iOS,学习(直播,文章,视频),iOS,控件)