IFTTT / RazzleDazzle

A simple keyframe-based animation framework for iOS, written in Swift. Perfect for scrolling app intros.
http://ifttt.github.io
MIT License
3.36k stars 292 forks source link

Issue with keeping a view in multiple pages #27

Closed lm2s closed 5 years ago

lm2s commented 8 years ago

Hello. I'm not being able to keep a label in multiple pages. I've also tried with a button and the result is the same. What happens is that the view is put way to the left in the scrollview even if only 1 page is set, e.g., keepView(label, pages: [2]). That is, when it should be in page 2 it appears in page 4 or 5 and a bit off center. What could be causing this?

keepView(label3, onPage: 2)

a_keepview_single

keepView(label3, onPages: [2])

b_keepview_pages
lauraskelton commented 8 years ago

Try deleting both of the self.centerX constraints- they conflict with what the keepView onPage is doing. Also be sure to avoid setting a left, right, leading, or trailing constraint on the view that you want to keep on a page.

lm2s commented 8 years ago

These horizontal constraints are being set by RazzleDazzle.

How I'm configuring the labels:

        let label3 = UILabel()
        label3.translatesAutoresizingMaskIntoConstraints = false
        label3.textAlignment = .Center
        label3.numberOfLines = 0
        label3.text = NSLocalizedString("Take a moment to comtemplate the mysteries of life while you wait.", comment: "")
        label3.font = UIFont.findsterNormalFont(18)
        label3.textColor = UIColor.whiteColor()
        contentView.addSubview(label3)
        let constraints_label3 = [
            NSLayoutConstraint(item: label3, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.CenterY, multiplier: 1.0, constant: 40.0),
            NSLayoutConstraint(item: label3, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: labelsWidth),
            NSLayoutConstraint(item: label3, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 100.0)
        ]
        contentView.addConstraints(constraints_label3)
        keepView(label3, onPage: 2)
        let label3 = UILabel()
        label3.translatesAutoresizingMaskIntoConstraints = false
        label3.textAlignment = .Center
        label3.numberOfLines = 0
        label3.text = NSLocalizedString("Take a moment to comtemplate the mysteries of life while you wait.", comment: "")
        label3.font = UIFont.findsterNormalFont(18)
        label3.textColor = UIColor.whiteColor()
        contentView.addSubview(label3)
        let constraints_label3 = [
            NSLayoutConstraint(item: label3, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.CenterY, multiplier: 1.0, constant: 40.0),
            NSLayoutConstraint(item: label3, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: labelsWidth),
            NSLayoutConstraint(item: label3, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 100.0)
        ]
        contentView.addConstraints(constraints_label3)
        keepView(label3, onPages: [2])
lm2s commented 8 years ago

This gets weirder. I created another screen where I only have one label (code is below) and the motion of the label is contrary to the motion of the drag as can be seen in this video https://infinit.io/_/6vqst2J

Is RazzleDazzle not compatible with XIBs?

import UIKit
import RazzleDazzle

class GPSModeHelpViewController: AnimatedPagingScrollViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        addViews()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    override func numberOfPages() -> Int {
        return 3
    }

    // MARK: -

    func addViews() {
        let screenWidth = UIScreen.mainScreen().bounds.width
        let labelsWidth = screenWidth * 0.9

        let titleLabel = UILabel()
        titleLabel.text = NSLocalizedString("Environment Type", comment: "gps mode help")
        contentView.addSubview(titleLabel)
        let constraints_titleLabel = [
            NSLayoutConstraint(item: titleLabel, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Top, multiplier: 1.0, constant: 40.0),
            NSLayoutConstraint(item: titleLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: labelsWidth),
            NSLayoutConstraint(item: titleLabel, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 60.0)
        ]
        contentView.addConstraints(constraints_titleLabel)
        keepView(titleLabel, onPages: [0,1,2])
    }
}