2016-09-30 8 views
1

私はSFSafariViewControllerを使用して、クッキーの動作が必要なのでウェブページを表示しています。私はそれを隠すオーバーレイといくつかのタスクを実行するいくつかのボタンがあるので、サファリ検索バーが欲しいわけではありません。私はボタンの機能が欲しいです。私たちはオーバーレイを持っているので、doneボタンは隠されていて動作していないので、私はこれをコードの下で試しました。 sfsafariviewcontrollerホームボタンがオーバーレイされていません

self.presentViewController(sfController, animated: true) { 
     let bounds = UIScreen.mainScreen().bounds 

     // It can be any overlay. May be your logo image here inside an imageView. 
     let overlay = UIView(frame: CGRect(x: 0, y: 0, width: bounds.size.width, height: 65)) 
     let completedBtn = UIButton() 
     let favBtn = UIButton() 
     let homeBtn = UIButton() 

     homeBtn.setTitle("Home",forState: .Normal) 
     homeBtn.setTitleColor(UIColor.whiteColor(), forState: .Normal) 
     homeBtn.frame = CGRectMake(20, 25, 200, 35) 
     homeBtn.backgroundColor = UIColor(netHex: 0x6F9824) 
     homeBtn.addTarget(self, action: #selector(DetailsViewController.HomeBtnAction), forControlEvents: UIControlEvents.TouchUpInside) 

     completedBtn.setTitle("Completed",forState: .Normal) 
     completedBtn.setTitleColor(UIColor.whiteColor(), forState: .Normal) 
     completedBtn.frame = CGRectMake((bounds.size.width - 210), 25, 200, 35) 
     completedBtn.backgroundColor = UIColor(netHex: 0x6F9824) 
     completedBtn.addTarget(self, action: #selector(DetailsViewController.CompletedAction), forControlEvents: UIControlEvents.TouchUpInside) 

     favBtn.setTitle("Favourite", forState: .Normal) 
     favBtn.setTitleColor(UIColor.whiteColor(), forState: .Normal) 
     favBtn.frame = CGRectMake((bounds.size.width - 420), 25, 200, 35) 
     favBtn.backgroundColor = UIColor(netHex: 0x6F9824) 
     favBtn.addTarget(self, action: #selector(DetailsViewController.FavouriteAction), forControlEvents: UIControlEvents.TouchUpInside) 

     overlay.backgroundColor = UIColor(netHex: 0x435C16) 

     overlay.addSubview(favBtn) 
     overlay.addSubview(completedBtn) 
     overlay.addSubview(homeBtn) 
     sfController.view.addSubview(overlay) 
} 

On click of Home button i have this code - 
func HomeBtnAction(){ 
     let app = "MyApp://" 
     let appUrl = NSURL(string: app) 
     if UIApplication.sharedApplication().canOpenURL(appUrl!) 
     { 
      UIApplication.sharedApplication().openURL(appUrl!) 

     } 
    } 
をそして私のplistのは、このようになります - - しかし、これは同様に機能していない

<key>LSApplicationQueriesSchemes</key> 
    <array> 
     <string>MyApp</string> 
    </array> 
    <key>CFBundleURLTypes</key> 
    <array> 
     <dict> 
      <key>CFBundleURLName</key> 
      <string>Test.com.MyApp</string> 
      <key>CFBundleURLSchemes</key> 
      <array> 
       <string>MyApp</string> 
      </array> 
     </dict> 
    </array> 

しかし、ホームボタンのクリック時に、何も起こりません。エラーや警告メッセージは表示されません。また、私はホームボタンをクリックして私の現在のコードは、再びアプリケーションを開くための警告を与えるだろう知っているが、私もそれを望んでいない。私はsfsafariviewcontrollerの "done"ボタンとまったく同じ機能が必要です。私たちはその仕事をして、私のオーバーレイも持てますか?

ありがとうございました!そして、どんな提案も大歓迎です。

+0

'SFSafariViewController'は、URLバーを無効にします。まだそこにはありますが、実際にはユーザーとして何も入力することはできないため、おそらくそれを隠す必要はありません。 –

答えて

1

なぜ、presentViewcontroller dismiss関数を呼び出さないのですか?私はswift 3を使ってこのソースコードをテストしました。それは私のために適切に働いており、私は自分のアプリケーションに戻ることができます。

func HomeBtnAction(){ 
 
     print("Button Pressed") 
 
     self.dismiss(animated: true, completion: nil) 
 
    }

+0

はい!なぜ私はそれについて考えるのか分かりません...ありがとうございました。あなたは素晴らしいです! –

関連する問題