简体   繁体   中英

Change UIImageView height on scroll

I need to resize imageview on scroll and tried some answers in stackoverflow but failed to implement those. Not sure what did I missed, please advice.

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
    int scrollY = scrollView.contentOffset.y;
    if (scrollY > 0) {
        _coverImgView.frame = CGRectMake(0, 23 + scrollY, 375, 139 - scrollY);
        _coverImgView.center = _coverImgView.superview.center;
    }
}

Sharing current configuration of my UIImageView

组态

Also sharing UI

UX

Let me know, your suggestions on this. Expecting UIImageView to reduce height onscroll.

When using auto-layout you shouldn't be directly setting the frame of any of your views, you should be changing the layout constraint constants to reposition and size your views and then updating the layout.

So, change the 'top' and 'height' constraints each time the delegate method is called, then layoutIfNeeded .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM