0

I'm interested in how to show/hide UIView when dragging and cling to the borders. What the method it was implemented, UIKit-UIDynamics?

enter image description here

Tikhonov Aleksandr
  • 13,945
  • 6
  • 39
  • 53
  • I haven't tried anything. I just want to find right way to implement it. I have one idea about using UIAttachmentBehavior and UICollisionBehavior, but I'm not sure that it's right way. – Tikhonov Aleksandr Sep 06 '15 at 08:09

2 Answers2

3

You need to animate a height constraint of the temperature label (or custom view, I don't know what that is).

So, just link an IBOutlet to the height constraint and animate it

func animateCloseWith(float: CGFloat) {
    UIView.animateWithDuration(0.3, animations: { () -> Void in
                self.myConstraint.constant = self.myConstraint.constant - float //for the height
                self.myView.alpha = Float(float) //for the fade effect
            })
}

then just call it from the scrollView delegate

optional func scrollViewDidScroll(_ scrollView: UIScrollView) {
    animateCloseWith(scrollView.contentOffset.y)
}
trusk
  • 1,634
  • 2
  • 18
  • 32
1

First of all:

Consider looking on the web for your solution before asking here on Stack!


I was developing an app in the past and found a neat solution for this. If you ask me: This repository looks exactly as the Yahoo-weather app which is about 90 similar to the apple weather app.

It is written in Obj-C, therefore I would suggest using Obj-C to implement it.

You just need to customize the views to get the clouds, suns, labels, horizontal scrollViews and all the other stuff.

To show/hide a UIView you could simply use scrollView.contentOffset in the scrollViewDidScroll method to show/hide the desired UILabel/UIView!

Check here: Get current position of animated scrollview

BTScrollView

Download the project and run the samples to test it! :)

Here you got an additonal screenshot:

enter image description here

Cheers!

Community
  • 1
  • 1
MasterRazer
  • 1,377
  • 3
  • 16
  • 40