简体   繁体   English

定义UIViewController或UIView的自定义框架

[英]Define custom frame of UIViewController or UIView

I'm doing a game in Swift 2.0 & iOS >= 8 in which I have the initial VC hosting the SKScene that manages the game itself. 我正在使用Swift 2.0和iOS> = 8进行游戏,在该游戏中,我有初始的VC托管着SKScene来管理游戏本身。

When the player wins or loses, I want to show a message as below : 当玩家赢或输时,我要显示以下消息:

在此处输入图片说明

I show this message through another VC loaded from the interface builder with the below code called from the initial VC class : 我通过接口构建器加载的另一个VC显示此消息,并使用以下代码从初始VC类调用:

let VCWin = self.storyboard!.instantiateViewControllerWithIdentifier("WinVC") as! WinVC
VCWin.modalPresentationStyle = UIModalPresentationStyle.FormSheet
VCWin.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
self.presentViewController(VCWin, animated: true, completion: nil)

It is important that WinVC allows to see what is behind dimmed as FormSheet & CrossDissolve properties enable to do. WinVC允许看到FormSheet和CrossDissolve属性启用后变暗的原因很重要。

WinVC will also host a view that presents a SKScene which does some sprite animations. WinVC还将主持一个视图,该视图呈现一个SKScene,该场景可以执行一些精灵动画。

My problem is to remove the white parts near the rounded yellow corners in order to see what is behind (like the rest of the screen that is dimmed). 我的问题是删除圆的黄色角附近的白色部分,以查看后面的内容(例如屏幕其余部分变暗)。

Is it possible to set the frame of a VC to the mask of the image used here ? 是否可以将VC的帧设置为此处使用的图像的遮罩? or to set the frame of a view to the mask of the image used and have the VC below transparent ? 还是将视图的框架设置为所用图像的遮罩,并使VC透明以下?

I have removed everything from WinVC to avoid having issues caused by other parts of the code 我已从WinVC中删除了所有内容,以避免由于代码的其他部分引起问题

class WinVC: UIViewController
{
    override func viewDidLoad()
    {
        super.viewDidLoad()
    }

    override func viewDidAppear(animated: Bool)
    {
    }

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
    {
        for _ in touches
        {
            self.dismissViewControllerAnimated(false, completion: nil)
        }
    }

    override func viewDidDisappear(animated: Bool)
    {
    }
}

Also the setup in the interface builder : 也是界面生成器中的设置:

VC Setup VC设置

在此处输入图片说明

view Setup 查看设置

在此处输入图片说明

Image Setup 影像设定

在此处输入图片说明

Your frame is fine - It's probably because your UIViewController contains a view object, that has a white background. 您的框架很好-可能是因为UIViewController包含一个具有白色背景的视图对象。 In your WinVC class's viewDidLoad , do this: WinVC类的viewDidLoad ,执行以下操作:

view.backgroundColor = UIcolor.clearColor()

I solved my issue with the following solution : 我通过以下解决方案解决了我的问题:

  • Set VCWin Presentation parameter to "Over full screen" 将VCWin Presentation参数设置为“全屏显示”
  • Set VCWin size to the same size as the VC it goes over 将VCWin大小设置为与其所经过的VC相同的大小
  • Set the background color of the SKView in VCWin to "Clear Color" 在VCWin中将SKView的背景色设置为“清除颜色”
  • The image used as background in the SKView has to have alpha where transparency is wanted (the corners in my case) 在SKView中用作背景的图像必须在需要透明度的位置具有Alpha(在我的情况下为四角)
  • Set the SKView size to the size of the image used as background 将SKView大小设置为用作背景的图像的大小
  • Create a ShapeNode with color/transparency correctly set-up and put it on top of the SKScene which is in the VC behind VCWin to do the dim effect 创建具有正确设置颜色/透明度的ShapeNode,并将其放在VCWin之后的VC中的SKScene的顶部,以执行暗淡效果

Then I have the wanted result : 然后我有想要的结果:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM