UIIViewの背景色を透過したい。
https://qiita.com/takehiro224/items/dc5903ae42f288ccd5f7
の記事を参考にメニューを作成しました。
記事内では背景色を Opacity:0.5
に設定するように書かれています。
が、Xcode(IDE)のStroyboardにがOpcaityは見当たらなくてAlphaしかありません。
そこの値を0.5にするも画面が真っ黒のままです。
その他にも...
試したこと
・Storyboard側のAplphaの数値を下げてみた
・Storyboard側のUIColorのOpacityの数値を下げてみた
・レイヤーの順番を確認
と試してBuildするも背景色は真っ黒です。
どうやったら背景色を透過できるのでしょうか。。
import UIKit class MenuViewController: UIViewController { @IBOutlet weak var menuView: UIView! override func viewDidLoad() { super.viewDidLoad() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) // メニュー画面の位置 let menuPosition = self.menuView.layer.position // 初期位置設定 self.menuView.layer.position.x = -self.menuView.frame.width // 表示アニメーション UIView.animate( withDuration: 0.1, delay: 0, options: .curveEaseOut, animations: { self.menuView.layer.position.x = menuPosition.x }, completion: { bool in }) } // メニュー外をタップした場合に非表示にする override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { super.touchesEnded(touches, with: event) for touch in touches { if touch.view?.tag == 1 { UIView.animate( withDuration: 0.2, delay: 0, options: .curveEaseIn, animations: { self.menuView.layer.position.x = -self.menuView.frame.width }, completion: { bool in self.dismiss(animated: true, completion: nil) } ) } } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }
// コード① let blackColor = UIColor.black let transparentBlackColor = blackColor.setAlpha(alpha: 0.5) self.view.backgroundColor = transparentBlackColor
コード①だと真っ黒になります。
UIColor.redにすると 赤黒
になります。
何の黒色が残っているのかがわかりません。。
実際のコードではPresentationは Full Screen
となっています。
回答1件
あなたの回答
tips
プレビュー