模态segue在触发时第一次缓慢

时间:2016-01-18 20:56:02

标签: ios swift uiviewcontroller segue

我已经为viewController创建了一个模态segue,但是当我触发这个segue时,在查看viewController时似乎有一些延迟。我在viewController中的所有内容都在viewDidLoad中。什么可以解决这种缓慢的模态?

override func viewDidLoad() {
    super.viewDidLoad()

    self.title = "Caption".uppercaseString

    self.view.backgroundColor = UIColor(hexString: "#0B1E30")

    self.navigationController?.navigationBar.barTintColor = UIColor(gradientStyle: UIGradientStyle.LeftToRight, withFrame: CGRectMake(0, 0, self.view.frame.width, (self.navigationController?.navigationBar.frame.height)! + 20), andColors: [UIColor(hexString: "#7F5CE6"), UIColor(hexString: "#9D8FE2")])

    let closeButton = UIBarButtonItem(image: UIImage(named: "Cross"), style: UIBarButtonItemStyle.Done, target: self, action: "dismissController")
    self.navigationItem.leftBarButtonItem = closeButton

    textView?.text = "Add caption (optional)"
    textView?.becomeFirstResponder()
    textView?.keyboardAppearance = UIKeyboardAppearance.Dark
    textView?.font = UIFont(name: "Montserrat-Light", size: 13)
    textView?.textColor = UIColor(hexString: "#363636")

    capturedImageView = UIImageView(image: capturedPhoto)
    capturedImageView?.frame = CGRectMake(8,10, 85, 85)
    let path = UIBezierPath(rect: CGRectMake(8, 10, 85, 85))
    textView?.textContainer.exclusionPaths = [path]
    textView?.addSubview(capturedImageView!)

    facebookButton?.tag = 1
    facebookButton!.adjustsImageWhenHighlighted = false
    facebookButton?.addTarget(self, action: "tapSocial:", forControlEvents: UIControlEvents.TouchUpInside)
    facebookButton?.tintColor = UIColor.whiteColor()
    facebookButton?.backgroundColor = UIColor(hexString: "#395798")
    facebookButton?.contentMode = UIViewContentMode.Center
    facebookButton?.setTitle("", forState: UIControlState.Normal)

    let fBorder = CALayer()
    let width = CGFloat(1.0)
    fBorder.borderColor = UIColor.whiteColor().colorWithAlphaComponent(0.05).CGColor
    fBorder.frame = CGRect(x: 0, y: facebookButton!.frame.size.height - width, width:  facebookButton!.frame.size.width, height: facebookButton!.frame.size.height)

    fBorder.borderWidth = width
    facebookButton!.layer.addSublayer(fBorder)
    facebookButton!.layer.masksToBounds = true


    twitterButton?.tag = 2
    twitterButton!.adjustsImageWhenHighlighted = false
    twitterButton?.addTarget(self, action: "tapSocial:", forControlEvents: UIControlEvents.TouchUpInside)
    twitterButton?.contentMode = UIViewContentMode.Center
    twitterButton?.tintColor = UIColor.whiteColor()
    twitterButton?.setTitle("", forState: UIControlState.Normal)

    let tBorder = CALayer()
    tBorder.borderColor = UIColor.whiteColor().colorWithAlphaComponent(0.05).CGColor
    tBorder.frame = CGRect(x: 0, y: twitterButton!.frame.size.height - width, width:  twitterButton!.frame.size.width, height: twitterButton!.frame.size.height)
    tBorder.borderWidth = width
    twitterButton!.layer.addSublayer(tBorder)
    twitterButton!.layer.masksToBounds = true

    let tRightBorder = CALayer()
    tRightBorder.borderColor = UIColor.whiteColor().colorWithAlphaComponent(0.05).CGColor
    tRightBorder.frame = CGRect(x: 0, y: 0, width:  width, height: twitterButton!.frame.size.height)

    tRightBorder.borderWidth = width
    twitterButton!.layer.addSublayer(tRightBorder)

    instagramButton?.tag = 3
    instagramButton!.adjustsImageWhenHighlighted = false
    instagramButton?.addTarget(self, action: "tapSocial:", forControlEvents: UIControlEvents.TouchUpInside)
    instagramButton?.contentMode = UIViewContentMode.Center
    instagramButton?.tintColor = UIColor.whiteColor()
    instagramButton?.setTitle("", forState: UIControlState.Normal)

    let iBorder = CALayer()
         iBorder.borderColor = UIColor.whiteColor().colorWithAlphaComponent(0.05).CGColor
    iBorder.frame = CGRect(x: 0, y: instagramButton!.frame.size.height - width, width:  instagramButton!.frame.size.width, height: instagramButton!.frame.size.height)

    iBorder.borderWidth = width
    instagramButton!.layer.addSublayer(iBorder)
    instagramButton!.layer.masksToBounds = true

    let iLeftBorder = CALayer()
    iLeftBorder.borderColor = UIColor.whiteColor().colorWithAlphaComponent(0.05).CGColor
    iLeftBorder.frame = CGRect(x: 0, y: 0, width:  width, height: instagramButton!.frame.size.height)

    iLeftBorder.borderWidth = width
    instagramButton!.layer.addSublayer(iLeftBorder)

}

1 个答案:

答案 0 :(得分:1)

这让我感到惊讶,但显然默认情况下设置为true时,textView的属性“可选”存在性能问题(在Storyboard上检查)。

尝试转到故事板,选择每个textView并取消选中“可选”框。如果您需要textView可选,那么只需在viewDidLoad上以编程方式将selectable设置为true。