ios - Swift Webview force landscape -


i create webview in xcode swift. want pages screen force rotates landscape. , pages auto orientation. how can this?

update

i did after answer of reinier:

func loadaddressurl(){     let requesturl = nsurl(string: urlpath)     let request = nsurlrequest(url: requesturl!)      //url name show in landscape mode     if(request.url?.absolutestring == baseurl + "dashboard")     {         print(request.description)          if(uidevice.currentdevice().orientation != uideviceorientation.landscaperight)         {             let value = uiinterfaceorientation.landscaperight.rawvalue             uidevice.currentdevice().setvalue(value, forkey: "orientation")          }     }      webview.loadrequest(request) 

but doesn't work. when turn device portrait, app rotate portrait want force landscape.

i had been working on question, , results, first of need notified when event of load new url happens method can achieve this, of course need set delegate of webview viewcontroller , implement method

func webview(webview: uiwebview, shouldstartloadwithrequest request: nsurlrequest, navigationtype: uiwebviewnavigationtype) -> bool 

this code

updated

to keep orientation need implement method func supportedinterfaceorientations() -> uiinterfaceorientationmask , keep in 1 variable orientation want


swift

import uikit  class viewcontroller: uiviewcontroller,uiwebviewdelegate {      @iboutlet weak var webview: uiwebview!     var termsweb = false     var validorientation : uiinterfaceorientationmask = uiinterfaceorientationmask.portrait     override func viewdidload() {         super.viewdidload()         // additional setup after loading view, typically nib.         self.loadwebview()     }      @ibaction func loadanotherweb(sender: anyobject) {         self.loadwebview()     }      func loadwebview()     {         let termsfilepath = nsbundle.mainbundle().pathforresource("terms_conditions", oftype: "html")                 {             var urlname = ""             if(termsweb)             {                 urlname = "terms"                 termsweb = !termsweb             }else             {                 urlname = "another"                 termsweb = !termsweb             }              let html = try string(contentsoffile: termsfilepath!)             webview.loaddata(html.datausingencoding(nsutf8stringencoding)!, mimetype: "text/html", textencodingname: "utf-8", baseurl: nsurl(string: urlname)!)         }catch         {          }     }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }      internal func webview(webview: uiwebview, shouldstartloadwithrequest request: nsurlrequest, navigationtype: uiwebviewnavigationtype) -> bool     {          //url name show in landscape mode         if(request.url?.absolutestring == "file://terms")         {             print(request.description)              if(uidevice.currentdevice().orientation != uideviceorientation.landscaperight)             {                 let value = uiinterfaceorientation.landscaperight.rawvalue                 self.validorientation = .landscape                 uidevice.currentdevice().setvalue(value, forkey: "orientation")             }         }          //url name show in modes         if(request.url?.absolutestring == "file://another")         {            self.validorientation = .all         }          return true     }      override func supportedinterfaceorientations() -> uiinterfaceorientationmask {         return self.validorientation     }  } 

i hope helps you


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -