iOS drop-down image zoom in

Source: Internet
Author: User

Start a simple code process

In fact, the idea is very simple is to let TableView offset the height of a picture, and then add the picture to the TableView, and then listen to Didscrollview, change the frame inside the picture

- (void) Viewdidload {[Super Viewdidload];Additional setup after loading the view, typically from a nib.Self. Automaticallyadjustsscrollviewinsets =NO; _tableview = [[UITableView Alloc]initwithframe:CGRectMake (0, NAVH,Cgrectgetwidth (Self. View. Frame),Cgrectgetheight (Self. View. Frame)-NAVH) style:Uitableviewstyleplain]; _tableview. Delegate =Self _tableview. DataSource =Self/* Set the offset of TableView **/_tableview. Contentinset =Uiedgeinsetsmake (STARTIMAGEVIEWH,0,0,0); [Self. View Addsubview:_tableview];*/* Note that the Y value of ImageView is-STARTIMAGEVIEWH actually this value is tableview content offset * If y is 0 then it will still follow TableView offset STARTIMAGEVIEWH value **/Uiimageview * ImageView = [[Uiimageview Alloc]initwithframe:CGRectMake (0,-STARTIMAGEVIEWH,Cgrectgetwidth (Self. View. frame), STARTIMAGEVIEWH)]; ImageView. image = [UIImage imagenamed:@ "1"];Self. ImageView = ImageView; [Self. TableView Addsubview:imageview];} - (void) Scrollviewdidscroll: (Uiscrollview *) ScrollView {CGFloat OffsetY = ScrollView. contentoffset. Y;NSLog (@ "OffsetY =%f", OffsetY);/* Calculate the offset **/when pulling downif (OffsetY <-STARTIMAGEVIEWH) {/* Calculate the difference value **/CGFloat interval =-Cgrectgetheight (Self. ImageView. frame)-OffsetY;/* ImageView height increased interval **/CGFloat IMAGEVIEWH =Cgrectgetheight (Self. ImageView. frame) + interval;/* Calculates the height of the ImageView after the increase in the width of the value **/CGFloat IMAGEVIEWW = imageviewh*Cgrectgetwidth (Self. ImageView. Frame)/Cgrectgetheight (Self. ImageView. frame);/* Calculates the offset of ImageView X **/CGFloat imageviewx =Self.imageview.frame.origin< Span class= "hljs-variable" >.x-(imagevieww-cgrectgetwidth ( self.imageview.frame))/< Span class= "Hljs-number" >2; /* calculates the offset of ImageView Y **/cgfloat imageviewy =self.imageview.frame .origin.y-interval; /* assignment **/self.imageView.frame = cgrectmake (imageviewx, Imageviewy, ImageViewW, IMAGEVIEWH); }} 

Demo Address: Https://github.com/lichory/pullDownImageView

This article is based on the author Li Chongyang _arc's article, which is written in order to make a backup copy in his blog.

iOS drop-down image zoom in

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.