IOS tableview drop-down image zoom in

Source: Internet
Author: User

In fact, this effect is essentially when you tableview down to create offset. Keep the y-coordinate point of your top picture in the drop-down screen vertex (offset), and the length of the picture changes to the original height length-(offset) to the pull-up effect.

Directly on the code:

1. First create a uiview as Headerview

_topview = [[UIViewalloc]initwithframe:cgrectmake(0, 0,mcappwidth)];

_tableview. Tableheaderview =_topview;

2. Next create a uiimageview put that picture

            _topimageview = [[ uiimageview alloc" initwithframe: CGRectMake ( 0 , 0 mcappwidth 80

_topimageview. Contentmode = Uiviewcontentmodescaleaspectfill;

_topimageview. Layer. Maskstobounds = YES;

            [ _topimageview sd_setimagewithurl:[ nsurl urlwithstring : nil ] placeholderimage:[ uiimage imagenamed : @ "MIAN_BG" ]];

[_topviewaddsubview:_topimageview];


3. Finally introduce the ScrollView agent method to monitor the change of frame

-(void) Scrollviewdidscroll: (uiscrollview *) ScrollView

{

if (_tableview = = ScrollView) {

CGFloat yoffset = _tableview. Contentoffset. Y;

Drop down image to enlarge

if (Yoffset < 0) {

         _topview . frame  = CGRectMake (0 , 0, mcappwidth ,  80  *  Height  -yoffset);

_topimageview. frame = cgrectmake(0, Yoffset, mcappwidth, * Height -Yoffset) ;

NSLog (@ "%.2f", _topimageview. y);

}

Else {

_topview. frame = cgrectmake(0, 0, mcappwidth, * Height - Yoffset);

_topimageview. y = yoffset * 0.65;

_topimageview. height = * Height -yoffset * 0.65;

}

}

}

What I'm doing here is that the relative displacement assumes that the next two lines of code need to be peered out of the other in the _TOPIMAGEVIEW.Y = _topview.y value remains the same.

I'm here. Y is your own encapsulation method direct copy will make an error.

IOS tableview 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.