美文网首页iOS UIKit框架学习uiwebview
iOS-UIKit框架学习—UIWebView

iOS-UIKit框架学习—UIWebView

作者: Wynter_Wang | 来源:发表于2017-03-01 10:09 被阅读7次

    您使用了UIWebView类,在您的应用程序中嵌入网页内容。要做到这一点,你只需创建一个UIWebView对象,将它附加到一个窗口,它发送一个请求加载网页内容。您也可以使用这个类在网页的历史向前和向后移动,你甚至可以设置一些网页内容属性的编程。

    @class UIWebViewInternal;
    @protocol UIWebViewDelegate;
    
    NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UIWebView : UIView <NSCoding, UIScrollViewDelegate>
    // 代理
    @property (nullable, nonatomic, assign) id <UIWebViewDelegate> delegate;
    // scrollView属性
    @property (nonatomic, readonly, strong) UIScrollView *scrollView NS_AVAILABLE_IOS(5_0);
    // 加载URL请求链接
    - (void)loadRequest:(NSURLRequest *)request;
    // 加载本地html字符串网页
    - (void)loadHTMLString:(NSString *)string baseURL:(nullable NSURL *)baseURL;
    // 加载本地NSData数据网页
    - (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL;
    // URL请求
    @property (nullable, nonatomic, readonly, strong) NSURLRequest *request;
    // 重载
    - (void)reload;
    // 停止加载
    - (void)stopLoading;
    // 后退到上一个界面
    - (void)goBack;
    // 前进到一个之前到过页面
    - (void)goForward;
    // 是否可以后退
    @property (nonatomic, readonly, getter=canGoBack) BOOL canGoBack;
    // 是否可以前进
    @property (nonatomic, readonly, getter=canGoForward) BOOL canGoForward;
    // 是否正在加载
    @property (nonatomic, readonly, getter=isLoading) BOOL loading;
    // 加载完成后调动,通过它可以很方便的操作UIWebView中的页面元素。参数script用来传进当前页面文件元素字符串,对传进来的字符串进行相应的操作
    - (nullable NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script;
    // 是否将页面内容缩放到当前屏幕适合的尺寸
    @property (nonatomic) BOOL scalesPageToFit;
    // 网页内容可识别类型,如邮箱、电话、网址
    @property (nonatomic) UIDataDetectorTypes dataDetectorTypes NS_AVAILABLE_IOS(3_0);
    // 是否使用网页内嵌的视频播放。为了内嵌视频播放,不仅仅需要在这个页面上设置这个属性,还需要在HTML的viedeo元素必须包含webkit-playsinline属性 iPhone默认值NO,iPad默认值是YES
    @property (nonatomic) BOOL allowsInlineMediaPlayback NS_AVAILABLE_IOS(4_0);
    // 是否自动播放视频还是用户手动播放视频 默认值是YES
    @property (nonatomic) BOOL mediaPlaybackRequiresUserAction NS_AVAILABLE_IOS(4_0);
    // 是否支持Air Play播放 默认值是YES
    @property (nonatomic) BOOL mediaPlaybackAllowsAirPlay NS_AVAILABLE_IOS(5_0);
    // 是否把网页渲染全部加载到内存中去处理 默认值是NO
    @property (nonatomic) BOOL suppressesIncrementalRendering NS_AVAILABLE_IOS(6_0);
    // 是否必须用户操作输入控件才会显示键盘 默认值是YES
    @property (nonatomic) BOOL keyboardDisplayRequiresUserAction NS_AVAILABLE_IOS(6_0);
    // 设置页面分页模型
    @property (nonatomic) UIWebPaginationMode paginationMode NS_AVAILABLE_IOS(7_0);
    // CSS采用的页面模式
    @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);
    // 是否网页自带的照片浏览器
    @property (nonatomic) BOOL allowsPictureInPictureMediaPlayback NS_AVAILABLE_IOS(9_0);
    // 按下连接是否显示连接的预览 默认值为NO
    @property (nonatomic) BOOL allowsLinkPreview NS_AVAILABLE_IOS(9_0);
    @end
    
    __TVOS_PROHIBITED @protocol UIWebViewDelegate <NSObject>
    
    @optional
    // 当开始加载网页的时候调用,可以拦截一些用户操作行为,返回YES代表允许加载,否则反之
    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
    // 开始加载网页时调用
    - (void)webViewDidStartLoad:(UIWebView *)webView;
    // 加载完成时调用
    - (void)webViewDidFinishLoad:(UIWebView *)webView;
    // 加载出错时调用
    - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
    
    @end
    
    
    // 导航行为类型
    typedef NS_ENUM(NSInteger, UIWebViewNavigationType) {
        UIWebViewNavigationTypeLinkClicked, // 点击了链接
        UIWebViewNavigationTypeFormSubmitted, // 提交表单
        UIWebViewNavigationTypeBackForward, // 前进或返回
        UIWebViewNavigationTypeReload, // 重载
        UIWebViewNavigationTypeFormResubmitted, // 再次提交
        UIWebViewNavigationTypeOther
    } __TVOS_PROHIBITED;
    
    // 翻页效果
    typedef NS_ENUM(NSInteger, UIWebPaginationMode) {
        UIWebPaginationModeUnpaginated, // 无
        UIWebPaginationModeLeftToRight, // 当内容超出View时,从左到右
        UIWebPaginationModeTopToBottom, // 当内容超出View时,从顶部到底部
        UIWebPaginationModeBottomToTop, // 当内容超出View时,从底部到顶部
        UIWebPaginationModeRightToLeft  // 当内容超出View时,从右到左
    } __TVOS_PROHIBITED;
    
    // 有css时页面样式类型
    typedef NS_ENUM(NSInteger, UIWebPaginationBreakingMode) {
        UIWebPaginationBreakingModePage, // 页面样式
        UIWebPaginationBreakingModeColumn // 圆柱样式
    } __TVOS_PROHIBITED;
    

    相关文章

      网友评论

        本文标题:iOS-UIKit框架学习—UIWebView

        本文链接:https://www.haomeiwen.com/subject/srrqgttx.html