Ios 迅速下降

Ios 迅速下降,ios,swift,uiviewanimation,uiviewanimationtransition,Ios,Swift,Uiviewanimation,Uiviewanimationtransition,全部, 我想创建一个下拉列表来存储UIScrollView等 我已经通过使用动画块做了很多这方面的工作-从x=30到x=400,因此它将长方体向下移动。当成功块运行时,它将UIScollview从hidden=false变为false。。因此,它会在完成动画后显示UIScoll视图 这是最好的方式吗?我正在努力取得这些成果 这是暴露的过滤器。因此,动画运行以降低蓝色,然后我取消隐藏滚动视图 这是滤光片未曝光时的图像。 导航条下面有一个蓝色的部分 有人能帮我吗?还是这是后台练习 如果您的目标是

全部,

我想创建一个下拉列表来存储UIScrollView等

我已经通过使用动画块做了很多这方面的工作-从x=30到x=400,因此它将长方体向下移动。当成功块运行时,它将UIScollview从hidden=false变为false。。因此,它会在完成动画后显示UIScoll视图

这是最好的方式吗?我正在努力取得这些成果

这是暴露的过滤器。因此,动画运行以降低蓝色,然后我取消隐藏滚动视图

这是滤光片未曝光时的图像。

导航条下面有一个蓝色的部分


有人能帮我吗?还是这是后台练习

如果您的目标是iOS 7或更高版本,您可以通过在下拉视图中放置两个具有不同优先级的高度约束来实现这一点,例如,显示状态的优先级750和下拉高度常量,隐藏状态的优先级700和0常量。接下来,要显示/隐藏下拉列表,只需调用以下函数:

func showView(dropDownView: UIView) {

    let constrains = (dropDownView.superview?.constraints() as [NSLayoutConstraint]) +
            (dropDownView.constraints() as [NSLayoutConstraint])
    for constrain  in constrains{

        if(constrain.priority == 650{

            constrain.priority = 750

       }

    }

    dropDownView.hidden = false
    UIView.animateWithDuration(0.4, animations: {
        dropDownView.alpha = 1
        dropDownView.superview?.layoutIfNeeded()
        }, completion: {
        (value: Bool) in

    })


}

func hideView(dropDownView: UIView) {

    let constrains = (dropDownView.superview?.constraints() as [NSLayoutConstraint]) +
            (dropDownView.constraints() as [NSLayoutConstraint])
    for constrain  in constrains{

        if(constrain.priority == 750{

            constrain.priority = 650

       }

    }

    UIView.animateWithDuration(0.4, animations: {
        dropDownView.alpha = 0
        dropDownView.superview?.layoutIfNeeded()
        }, completion: {
        (value: Bool) in
        dropDownView.hidden = true                       
    })


}

这个问题现在有点老了,但如果有人来问同样的问题。 我建议你一定要看看这篇文章

请感谢原作者马诺利亚

和吉特回购

我最喜欢的是

示例代码

只需创建菜单控件

   class MenuViewController: UIViewController, GuillotineMenu {
    //GuillotineMenu protocol
    var dismissButton: UIButton!
    var titleLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        dismissButton = UIButton(frame: CGRectZero)
        dismissButton.setImage(UIImage(named: "ic_menu"), forState: .Normal)
        dismissButton.addTarget(self, action: "dismissButtonTapped:", forControlEvents: .TouchUpInside)

        titleLabel = UILabel()
        titleLabel.numberOfLines = 1;
        titleLabel.text = "Activity"
        titleLabel.font = UIFont.boldSystemFontOfSize(17)
        titleLabel.textColor = UIColor.whiteColor()
        titleLabel.sizeToFit()
    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        print("Menu: viewWillAppear")
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        print("Menu: viewDidAppear")
    }

    override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
        print("Menu: viewWillDisappear")
    }

    override func viewDidDisappear(animated: Bool) {
        super.viewDidDisappear(animated)
        print("Menu: viewDidDisappear")
    }

    func dismissButtonTapped(sende: UIButton) {
        self.presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
    }

    @IBAction func menuButtonTapped(sender: UIButton) {
        self.presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
    }

    @IBAction func closeMenu(sender: UIButton) {
        self.presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
    }

}

extension MenuViewController: GuillotineAnimationDelegate {
    func animatorDidFinishPresentation(animator: GuillotineTransitionAnimation) {
        print("menuDidFinishPresentation")
    }
    func animatorDidFinishDismissal(animator: GuillotineTransitionAnimation) {
        print("menuDidFinishDismissal")
    }

    func animatorWillStartPresentation(animator: GuillotineTransitionAnimation) {
        print("willStartPresentation")
    }

    func animatorWillStartDismissal(animator: GuillotineTransitionAnimation) {
        print("willStartDismissal")
    }
}
并以这种方式在视图控制器中使用上述内容

class ViewController: UIViewController {

    let reuseIdentifier = "ContentCell"
    private let cellHeight: CGFloat = 210
    private let cellSpacing: CGFloat = 20
    private lazy var presentationAnimator = GuillotineTransitionAnimation()

    @IBOutlet var barButton: UIButton!

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        print("VC: viewWillAppear")
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        print("VC: viewDidAppear")
    }

    override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
        print("VC: viewWillDisappear")
    }

    override func viewDidDisappear(animated: Bool) {
        super.viewDidDisappear(animated)
        print("VC: viewDidDisappear")
    }


    override func viewDidLoad() {
        super.viewDidLoad()
        let navBar = self.navigationController!.navigationBar
        navBar.barTintColor = UIColor(red: 65.0 / 255.0, green: 62.0 / 255.0, blue: 79.0 / 255.0, alpha: 1)
        navBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
    }

    @IBAction func showMenuAction(sender: UIButton) {
        let menuVC = storyboard!.instantiateViewControllerWithIdentifier("MenuViewController")
        menuVC.modalPresentationStyle = .Custom
        menuVC.transitioningDelegate = self
        if menuVC is GuillotineAnimationDelegate {
            presentationAnimator.animationDelegate = menuVC as? GuillotineAnimationDelegate
        }
        presentationAnimator.supportView = self.navigationController?.navigationBar
        presentationAnimator.presentButton = sender
        presentationAnimator.duration = 0.6
        self.presentViewController(menuVC, animated: true, completion: nil)
    }
}

// The following is just for the presentation. You can ignore it
extension ViewController: UICollectionViewDataSource, UICollectionViewDelegate {

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 5
    }

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell: AnyObject? = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath)
        return cell as! UICollectionViewCell!
    }

    func collectionView(collectionView: UICollectionView,
                        layout collectionViewLayout: UICollectionViewLayout,
                        sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        return CGSizeMake(CGRectGetWidth(collectionView.bounds) - cellSpacing, cellHeight)
    }
}

extension ViewController: UIViewControllerTransitioningDelegate {

    func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        presentationAnimator.mode = .Presentation
        return presentationAnimator
    }

    func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        presentationAnimator.mode = .Dismissal
        return presentationAnimator
    }
}

嗨,泽尔布,我正在使用ios7+,我想我应该看看NSLayoutConstrait,因为我不太确定它是什么。