One way to do it. IOS pull down zoom and push shrink _ios

Source: Internet
Author: User

The following effects are common in iOS applications:

Realize the idea:

1、 to create a head view and TableView, It is necessary to note that TableView to set contentinset,contentinsent The top is the same as the height of the background image of the head view, otherwise there will be gaps (or occlusion).

Mytableview.contentinset = Uiedgeinsetsmake (headrect.size.height-navheight-navheight, 0, 0, 0);

2、 to the head view of the background image of the size of the processing, of course, you can also directly find a suitable size of the picture, you do not have to deal with the picture, in order to increase the program's extensibility, I casually selected a picture, and the image size processing.

 UIImage * image = [uiimage imagenamed:name];
 UIImage * newimg = [self image:image byScalingToSize:self.bounds.size];
 Backgroundview.image = newimg;
 Backgroundview.clipstobounds = yes;//cut off the extra parts of the picture
Processing picture Methods
-(UIImage *) Image: (uiimage*) Image byscalingtosize: (cgsize) targetsize {uiimage
  *sourceimage = image ;
  UIImage *newimage = nil;

  Uigraphicsbeginimagecontext (targetsize);

  CGRect thumbnailrect = Cgrectzero;
  Thumbnailrect.origin = Cgpointzero;
  ThumbnailRect.size.width = Targetsize.width;
  ThumbnailRect.size.height = targetsize.height;

  [Sourceimage Drawinrect:thumbnailrect];

  NewImage = Uigraphicsgetimagefromcurrentimagecontext ();
  Uigraphicsendimagecontext ();

  return newimage;
}

3. This is done, the preparation is completed, next, a method to achieve our lower pull amplification, push and shrink function, of course, the focus and difficulty is logic, technology is easy. We all know that UITableView is inherited Uiscrollview , using the Uiscrollview Agent method - (void)scrollViewDidScroll:(UIScrollView *)scrollView; to achieve.

Pull Zoom In

In this method, we will be divided into two parts, one is the drop-down amplification, this is relatively easy, that is, the head view of the background image to enlarge, adjust the frame, you need to note that in this need to adjust the picture display mode, because the drop and push in the picture displayed in different ways, Otherwise, even if you adjust the frame, it will not be displayed according to the frame .

 _myview.backgroundview.contentmode = Uiviewcontentmodescaletofill;

 _myview.backgroundview.frame = CGRectMake (offset_y*0.5,-navheight, vcwidth-offset_y, headrect.size.height-offset_y );

Push up Move shrink

This is more difficult to understand, of course, I am talking about the middle of the frame algorithm, we have three views separately said.

1. Background Image: first toggle the display mode, and then the Y with TableView offset to move to 0, the height is also with TableView offset, the final move to the desired height (demo left is 44)

_myview.backgroundview.contentmode = Uiviewcontentmodetop;

_myview.backgroundview.frame = CGRectMake (0, navheight* offset_y/(headrect.size.height-navheight-navheight)- Navheight; , Vcwidth, HeadRect.size.height-(navheight + navheight* offset_y/(headrect.size.height-navheight-navheight)- Navheight)-offset_y);

2. Avatar: Avatar needs to move its position with the TableView offset and also to shrink. This is the relationship of a linear equation, which is the same as the background image above.

CGFloat width = offset_y* (40-(VCWIDTH/4))/(Headrect.size.height-navheight-navheight) + (VCWIDTH/4);
_myview.headview.frame =cgrectmake (0, 0, width,width);
_myview.headview.layer.cornerradius =width*0.5;
_myview.headview.center = _myview.backgroundview.center;

3. Signature: The signature is relatively simple, just follow the avatar move on the line, and then adjust their transparency based on the offset.

_myview.signlabel.frame =cgrectmake (0, Cgrectgetmaxy (_myview.headview.frame), Vcwidth,);

_myview.signlabel.alpha = 1-(Offset_y*3/(Headrect.size.height-navheight-navheight)/2);

Okay, and then it's done, the logic is very troublesome, but there is a junior high school math level is enough, because it is simply linear relationship. I hope this article for you to learn about the development of iOS help.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.