An explanation of the use of UIWebView in iOS
Last Update:2015-06-23
Source: Internet
Author: User
<span id="Label3"></p><span id="OSC_h2_1"><span id="OSC_h2_1"></span></span>An explanation of the use of UIWebView in iOS<span id="OSC_h3_2"><span id="OSC_h3_2"></span></span>first, Initialize and three kinds of loading methods<br> <p><p><span style="font-size: 16px;">UIWebView inherits from the uiview, so its initialization method, like the normal view, is initialized by Alloc and Init with three ways of loading the Data:</span></p></p> <p><p><span style="font-size: 16px;">The first type:</span></p></p> <p><p><span style="font-family: Menlo; font-size: 18px; line-height: normal;">-(</span><span style="font-family: Menlo; font-size: 18px; line-height: normal; color: rgb(195, 34, 117);">void</span><span style="font-family: Menlo; font-size: 18px; line-height: normal;">) loadrequest: (</span> <span style="font-family: Menlo; font-size: 18px; line-height: normal; color: rgb(97, 34, 174);">nsurlrequest</span> <span style="font-family: Menlo; font-size: 18px; line-height: normal;">*) request;</span></p></p> <p><p><span style="font-size: 16px;">This is the most common way to load a webpage, through a Web page URL to load, this URL can be remote or local, such as I load Baidu's homepage:</span><br></p></p> <pre class="brush:cpp;toolbar: true; auto-links: false;"><pre class="brush:cpp;toolbar: true; auto-links: false;">UIWebView * view = [[uiwebview alloc]initwithframe:self.view.frame]; [view loadrequest:[nsurlrequest Requestwithurl:[nsurl urlwithstring:@ "http://www.baidu.com"]]; [self.view addsubview:view];</pre></pre> <p><p><span style="font-size: 16px;">Will get the following effect:</span><br></p></p> <p><p></p></p> <p><p><span style="font-size: 16px;"><br></span></p></p> <p><p><span style="font-size: 16px;">The second type:</span></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">-(<span style="color: #c32275">void</span>) loadhtmlstring: (<span style="color: #6122ae">nsstring</span> *) string baseURL: (<span style="color: #6122ae">nsurl</span> *) baseURL;</p></p> <p><p><span style="font-size: 16px;">This method needs to read the httml file as a string, where BaseURL is a path we set ourselves to look for footage such as images referenced in an HTML file.</span></p></p> <p><p><span style="font-size:16px">The third type:</span></p></p> <p><p><span style="font-size:16px"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">-(<span style="color: #c32275">void</span>) Loaddata: (<span style="color: #6122ae">nsdata</span> *) data MIMEType: (<span style="color: #6122ae">nsstring</span> *) MIMEType textencodingname: ( <span style="color: #6122ae"> NSString</span> *) textencodingname baseURL: (<span style="color: #6122ae">nsurl</span> *) baseURL;</p></p> <p><p><span style="font-size:16px"></span><span style="font-size: 16px;">This method uses less, but also more freely, where data is the file, mimetype is the file type, textencodingname is the encoding type, and BaseURL is the asset path.</span><br></p></p> <span id="OSC_h3_3"><span id="OSC_h3_3"></span></span><span style="font-size: 18px;"><span style="font-size: 18px;">Ii. Some common properties and variables</span></span><span style="font-size: 16px;"><span style="font-size: 16px;"><br></span></span> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);">@property<span style="color: #000000"> (</span>nonatomic<span style="color: #000000">, </span>assign<span style="color: #000000">) </span>ID<span style="color: #000000"> <</span><span style="color: #6122ae">uiwebviewdelegate</span><span style="color: #000000">> delegate;</span></p></p> <p><p><span style="font-size: 16px;"></span><span style="font-size: 16px;">Set up a proxy for WebView</span></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);">@property<span style="color: #000000"> (</span>nonatomic<span style="color: #000000">, </span>readonly<span style="color: #000000">, </span>retain<span style="color: #000000">) </span> <span style="color: #6122ae">uiscrollview</span> <span style="color: #000000"> *scrollview;</span></p></p> <p><p><span style="font-size: 16px;"><span style="font-size: 16px; line-height: 22.5px;">Built-in ScrollView</span></span></p></p> <p><p><span style="font-size: 16px;"><span style="font-size: 16px; line-height: 22.5px;"></span></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);">@property<span style="color: #000000"> (</span>nonatomic<span style="color: #000000">, </span>readonly<span style="color: #000000">, </span>retain<span style="color: #000000">) </span> <span style="color: #6122ae">nsurlrequest</span> <span style="color: #000000"> *request;</span></p></p> <p><p><span style="font-size: 16px; line-height: 22.5px;"></span><span style="font-size: 16px;">URL Request</span></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">-(<span style="color: #c32275">void</span>) reload;</p></p> <p><p><span style="font-size: 16px;"></span><span style="font-size: 16px;">Reload data</span></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">-(<span style="color: #c32275">void</span>) stoploading;</p></p> <p><p><span style="font-size: 16px;">Stop loading Data</span><br></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">-(<span style="color: #c32275">void</span>) goBack;</p></p> <p><p><span style="font-size: 16px;"></span><span style="font-size: 16px;">Back to previous level</span></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">-(<span style="color: #c32275">void</span>) goForward;</p></p> <p><p><span style="font-size: 16px;">Jump to the next level</span><br><span style="font-size: 16px;"></span></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);">@property<span style="color: #000000"> (</span>nonatomic<span style="color: #000000">, </span>readonly<span style="color: #000000">, </span>getter<span style="color: #000000">=cangoback) </span>BOOL<span style="color: #000000"> cangoback;</span></p></p> <p><p><span style="font-size: 16px;">Gets whether to return to the previous level</span><br></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);">@property<span style="color: #000000"> (</span>nonatomic<span style="color: #000000">, </span>readonly<span style="color: #000000">, </span>getter<span style="color: #000000">=cangoforward) </span>BOOL<span style="color: #000000"> cangoforward;</span></p></p> <p><p><span style="font-size: 16px;">Gets whether to jump to the next level</span><br></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);">@property<span style="color: #000000"> (</span>nonatomic<span style="color: #000000">, </span>readonly<span style="color: #000000">, </span>getter<span style="color: #000000">=isloading) </span>BOOL<span style="color: #000000"> loading;</span></p></p> <p><p><span style="font-size: 16px;">Gets whether the data is being loaded</span><br></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">-(<span style="color: #6122ae">nsstring</span> *) stringbyevaluatingjavascriptfromstring: (<span style="color: #6122ae">nsstring</span> *) script;</p></p> <p><p><span style="font-size: 16px;">Manipulating Web data through JavaScript</span><br></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);">@property<span style="color: #000000"> (</span>nonatomic<span style="color: #000000">) </span>BOOL<span style="color: #000000"> scalespagetofit;</span></p></p> <p><p><span style="font-size: 16px;">Set whether to scale to fit the screen size</span><br></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="color: #c32275">@property</span> (<span style="color: #c32275">nonatomic</span>) <span style="color: #703daa">uidatadetectortypes</span> datadetectortypes <span style="color: #78492a">ns_available_ios</span>(<span style="color: #0435ff">3</span>_0);</p></p> <p><p><span style="font-size: 16px;">Set some data into link form, This enumeration can be set such as phone number, address, mailbox and so on into a link</span><br></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="color: #c32275">@property</span> (<span style="color: #c32275">nonatomic</span>) <span style="color: #c32275">BOOL</span> allowsinlinemediaplayback <span style="color: #78492a">ns_available_ios</span>(<span style="color: #0435ff">4</span>_0);</p></p> <p><p><span style="font-size: 16px;">Set whether to play a video using an inline player</span><br></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="color: #c32275">@property</span> (<span style="color: #c32275">nonatomic</span>) <span style="color: #c32275">BOOL</span> mediaplaybackrequiresuseraction <span style="color: #78492a">ns_available_ios</span>(<span style="color: #0435ff">4</span>_0);</p></p> <p><p><span style="font-size: 16px;">Set whether video plays automatically</span><br></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="color: #c32275">@property</span> (<span style="color: #c32275">nonatomic</span>) <span style="color: #c32275">BOOL</span> mediaplaybackallowsairplay <span style="color: #78492a">ns_available_ios</span>(<span style="color: #0435ff">5</span>_0);</p></p> <p><p><span style="font-size: 16px;"></span><span style="font-size: 16px;">Set whether audio playback supports the ARI Play feature</span></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="color: #c32275">@property</span> (<span style="color: #c32275">nonatomic</span>) <span style="color: #c32275">BOOL</span> suppressesincrementalrendering <span style="color: #78492a">ns_available_ios</span>(<span style="color: #0435ff">6</span>_0);</p></p> <p><p><span style="font-size: 16px;">Sets whether to load data such as In-memory render interface</span><br></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="color: #c32275">@property</span> (<span style="color: #c32275">nonatomic</span>) <span style="color: #c32275">BOOL</span> keyboarddisplayrequiresuseraction <span style="color: #78492a">ns_available_ios</span>(<span style="color: #0435ff">6</span>_0);</p></p> <p><p><span style="font-size: 16px;">Set User interaction Mode</span><br></p></p> <span id="OSC_h3_4"><span id="OSC_h3_4"></span></span><span style="font-size: 16px;"><span style="font-size: 16px;"> <span style="font-size: 18px;">Iii. Some new features in IOS7</span><br></span></span> <p><p><span style="font-size: 18px;"><span style="font-size: 16px;">The following properties are available after iOS7, through which they can set up a more interesting web experience</span><br></span></p></p> <p><p><span style="font-size: 18px;"><span style="font-size: 16px;"></span></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="color: #c32275">@property</span> (<span style="color: #c32275">nonatomic</span>) <span style="color: #703daa">uiwebpaginationmode</span> paginationmode <span style="color: #78492a">ns_available_ios</span>(<span style="color: #0435ff">7</span>_0);</p></p> <p><p><span style="font-size: 16px;">This property is used to set a pattern that, when the size of a page exceeds the view, displays the page as the effect of page flipping, enumerated as Follows:</span><br></p></p> <pre class="brush:cpp;toolbar: true; auto-links: false;"><pre class="brush:cpp;toolbar: true; auto-links: false;">typedef ns_enum (nsinteger, Uiwebpaginationmode) {uiwebpaginationmodeunpaginated,//do not use page flipping effects UIWEBPAGINATIONMODELEFTT Oright,//page out of partial paging, left-to-right page uiwebpaginationmodetoptobottom,//pages out of partial pagination, from top to bottom page uiwebpaginationmodebottomtotop,/ /page out of partial paging, from the bottom up to page uiwebpaginationmoderighttoleft//the page beyond the partial paging, from right to left page};</pre></pre> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="color: #c32275">@property</span> (<span style="color: #c32275">nonatomic</span>) <span style="color: #703daa">cgfloat</span> pagelength <span style="color: #78492a">ns_available_ios</span>(<span style="color: #0435ff">7</span>_0);</p></p> <p><p><span style="font-size: 16px;">Set the length of each page</span><br></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="color: #c32275">@property</span> (<span style="color: #c32275">nonatomic</span>) <span style="color: #703daa">cgfloat</span> gapbetweenpages <span style="color: #78492a">ns_available_ios</span>(<span style="color: #0435ff">7</span>_0);</p></p> <p><p><span style="font-size: 16px;"></span><span style="font-size: 16px;">Set the spacing for each page</span></p></p> <p><p><span style="font-size: 16px;"></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);">@property<span style="color: #000000"> (</span>nonatomic<span style="color: #000000">, </span>readonly<span style="color: #000000">) </span> <span style="color: #703daa">nsuinteger</span> <span style="color: #000000"> pagecount </span> <span style="color: #78492a">ns_available_ IOS</span><span style="color: #000000">(</span><span style="color: #0435ff">7</span><span style="color: #000000">_0);</span></p></p> <p><p><span style="font-size: 16px;"></span><span style="font-size: 16px;">Get the number of pages</span></p></p> <p><p><span style="font-size: 16px;"><br></span></p></p> <span id="OSC_h3_5"><span id="OSC_h3_5"></span></span><span style="font-size: 16px;"><span style="font-size: 16px;"><span style="font-size: 18px;">Iv. methods in the WebView protocol</span><br></span></span> <p><p><span style="font-size: 18px;"><span style="font-size: 16px;"></span></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">-(<span style="color: #c32275">BOOL</span>) webView: (<span style="color: #6122ae">uiwebview</span> *) webView shouldstartloadwithrequest: (<span style="color: #6122ae">nsurlrequest</span> *) Request Navigationtype: (<span style="color: #703daa">uiwebviewnavigationtype</span>) navigationtype;</p></p> <p><p><span style="font-size: 18px;"><span style="font-size: 16px;"></span><span style="font-size: 16px;">The method that is called when the content is ready to be loaded, and the settings that are loaded by the return value</span></span></p></p> <p><p></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">-(<span style="color: #c32275">void</span>) webviewdidstartload: (<span style="color: #6122ae">uiwebview</span> *) webView;</p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-size: 16px;">method to invoke when loading starts</span><br></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><br></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">-(<span style="color: #c32275">void</span>) webviewdidfinishload: (<span style="color: #6122ae">uiwebview</span> *) webView;</p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-size: 16px;">Method called when the load is ended</span><br></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-size: 16px;"><br></span></p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">-(<span style="color: #c32275">void</span>) webView: (<span style="color: #6122ae">uiwebview</span> *) webView didfailloadwitherror: (<span style="color: #6122ae">nserror</span> *) error;</p></p> <p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span style="font-size: 16px;">Methods that are called when a load fails</span><br></p></p> <p><p><br><br></p></p><p><p>An explanation of the use of UIWebView in iOS</p></p></span>