Kubba
Kubba

Reputation: 3438

setting frame in swift doesn't work as expected

I'm porting an app from Objective-C into pure Swift and I'm facing strange problem.

I've got AlertView class which is replacement for standard UIAlertView (now UIAlertController) for displaying animatable popups. AlertView is created in UIViewController extension - it's inited with view controller's view frame and added as a subview.

AlertView has a property which is a PopupView's instance - custom UIView subclass with xib (on Autolayout). This popup should has dynamic height depends on its contents (multiline message label).

Now when I'm trying to animate this popup in AlertView class:

What can be wrong here?

EDIT Showing popup method:

private func showPopup(popupView: PopupView)
{
    var beginFrame = popupView.frame
    beginFrame.origin.y = -beginFrame.size.height
    beginFrame.origin.x = self.bounds.size.width/2 - beginFrame.width/2
    popupView.frame = beginFrame

    var endFrame = beginFrame
    endFrame.origin.y = self.bounds.size.height/2 - endFrame.size.height/2

    popupView.hidden = false
    DLog(beginFrame)

    UIView.animateWithDuration(kAnimationTime, delay: 0, usingSpringWithDamping: kAnimationDamping, initialSpringVelocity: kAnimationSpringVelocity, options: UIViewAnimationOptions.CurveEaseIn, animations:
        { () -> Void in
            DLog(endFrame)
            popupView.frame = endFrame
    }, completion: nil)
}

in both cases it shows in console:

(72.5, -155.0, 230.0, 155.0)

(72.5, 256.0, 230.0, 155.0)

EDIT2

setTranslatesAutoresizingMaskIntoConstraints(false)

set-false

setTranslatesAutoresizingMaskIntoConstraints(true)

set-true

Upvotes: 0

Views: 1311

Answers (1)

Kubba
Kubba

Reputation: 3438

Ok, got solution. I've stopped mixing autolayout and direct frame modifications and use pure autolayout instead.

Upvotes: 1

Related Questions