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