1

I am trying to add the Instagram like animation on my app that minimizes the title "Instagram" and moves the display to the entire page.

In my app, i have two UILabels - chapterNameNumberLabel and chapterNameLabels and a UITextView. On scrolling in the UITextView, i want the chapterNameNumberLabel and the chapterNameLabels to minimize and the entire page to be filled with the UITextView contents.

I have tried the below:(used pointers mentioned in the answer here Finding the direction of scrolling in a UIScrollView?

Obtained the below in viewDidLoad():

 xLabel = self.chapNameNumberLabel.center.x;
    yLabel = self.chapNameNumberLabel.center.y;
    widthLabel = self.chapNameNumberLabel.frame.width;
    heightLabel = self.chapNameNumberLabel.frame.height;

    xNameLabel = self.chapterNameLabel.center.x;
    yNameLabel = self.chapterNameLabel.center.y;
    widthNameLabel = self.chapterNameLabel.frame.width;
    heightNameLabel = self.chapterNameLabel.frame.height;

And called the below method:

func scrollViewDidScroll(scrollView: UIScrollView) {

    if(self.lastContentOffset > 0 ){
        if (self.lastContentOffset > scrollView.contentOffset.y) {
            //print("Up");

            UIView.animateWithDuration(0.5, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: {
                self.chapNameNumberLabel.frame = CGRectMake(self.xLabel - 100, self.yLabel - 10, self.widthLabel, self.heightLabel);
                self.chapterNameLabel.frame = CGRectMake(self.xNameLabel - 140, self.yNameLabel - 10 , self.widthNameLabel, self.heightNameLabel);
                }, completion: nil)
        }
        else if (self.lastContentOffset < scrollView.contentOffset.y){
            print("Down");

            UIView.animateWithDuration(0.5, delay: 0.0, options: UIViewAnimationOptions.CurveEaseIn, animations: {
                self.chapNameNumberLabel.frame = CGRectMake( 100 , -10, 5, 5);
                self.chapterNameLabel.frame = CGRectMake(50, -10, 5, 5);

                }, completion: nil);
        }

    }
    // update the new position acquired
    self.lastContentOffset = scrollView.contentOffset.y

}

The animation is okay, but the problem that i am facing are:

  1. I am unable to get the 'font size minimizing' effect on the labels. The labels in my app just disappear without reducing the font size. What animation type should be used for achieving this font size minimization on scrolling?

  2. Also, the values that i have set on scrolling down(within the scrollViewDidScroll) are

self.chapNameNumberLabel.frame = CGRectMake( 100 , -10, 5, 5); self.chapterNameLabel.frame = CGRectMake(50, -10, 5, 5); and on scrolling up are trial and error values. The labels are not properly aligned when i rotate the screen left and right(on simulator). Could some one please tell me how to calculate this so that it works on all screen orientations?

I have used Swift 2 , Auto layout.

Community
  • 1
  • 1
Kavisha
  • 73
  • 8

0 Answers0