在Swift中设置呈现模式的自定义大小失败 - 占据全屏

时间:2017-06-01 08:41:18

标签: ios iphone swift

如何获得自定义尺寸的演示模式?尝试了许多不同的解决方案,其中许多似乎过时了

这是我从父视图控制器实例化模态视图的方法:

Sub Create_New_Excel_and_Disable_Properties()
'<~ Declare and prepare the new application
  Dim NewExcel As Excel.Application
  Set NewExcel = New Excel.Application

'<~ declare and set the workbook variable
Dim ExcelWbk As Excel.Workbook
Set ExcelWbk = NewExcel.Workbooks.Open("folder\template.xlsx")

'<~ call the sub that disables the Application.properties
OPTIMIZE_VBA False, NewExcel
End Sub

但是,模态视图覆盖全屏而不是仅占用100 * 100。

1 个答案:

答案 0 :(得分:1)

您需要实施UIViewControllerTransitioningDelegate方法和UIViewControllerAnimatedTransitioning方法来自定义显示的UIViewController尺寸。

要知道如何实现自定义动画师,

请参阅:https://github.com/pgpt10/Custom-Animator

修改

class ViewController: UIViewController
{
    //MARK: Private Properties
    fileprivate let animator = Animator()

    //MARK: View Lifecycle Methods
    override func viewDidLoad()
    {
        super.viewDidLoad()
    }

    override func awakeFromNib()
    {
        super.awakeFromNib()
        self.transitioningDelegate = self
        self.modalPresentationStyle = .custom
    }

    //MARK: Button Action Methods
    @IBAction func dismissController(_ sender: UIButton)
    {
        self.dismiss(animated: true, completion: nil)
    }
}

// MARK: - UIViewControllerTransitioningDelegate Methods
extension ViewController : UIViewControllerTransitioningDelegate
{
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning?
    {
        self.animator.transitionType = .zoom
        self.animator.size = CGSize(width: 100, height: 100)
        return self.animator
    }

    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning?
    {
        return self.animator
    }
}