Hover of internal controls in ScrollView

Source: Internet
Author: User

For example, picture, red View and blue View are added on ScrollView, drag upward, red view stays on top of screen, others continue scrolling, drag down, red view follows down

The code is as follows: (Note the setup problem for automatic layout in ScrollView)

 1 #import "ViewController.h" 2 @interface Viewcontroller () <UIScrollViewDelegate> 3 @property (weak, nonatomic) IB Outlet Uiscrollview *scrollview; 4 @property (weak, nonatomic) Iboutlet UIView *blueview; 5 @property (weak, nonatomic) Iboutlet UIView *redview; 6 @property (weak, nonatomic) Iboutlet Uiimageview *imageview; 7 @end 8 @implementation Viewcontroller 9-(void) Viewdidload {Ten [Super viewdidload];11 Self.scrollView.contentSi ze = cgsizemake (0, Cgrectgetmaxy (self.blueView.frame));}13-(void) Scrollviewdidscroll: (Uiscrollview *) SCROLLVIEW15 {cgfloat Imageh = self.imageview.frame.size.height;17 cgfloat OffsetY = Scrollview.contentoffset.y         if (OffsetY >= imageh) {19//Add Red Control to Controller view CGRect Redframe = self.redview.frame;21 REDFRAME.ORIGIN.Y = 0;22 Self.redView.frame = redframe;23 [Self.view addsubview:self.redview];24}els e {25//Add a red control to the controller ScrollView cgrect redframe = self.redview.frame;27 REDFRAME.ORIGIN.Y = 140;28 self.redView.frame = redframe;29 [Self.scrollview AddS        Ubview:self.redview];30}31//if (OffsetY < 0) {//CGFloat scale = 1-(OFFSETY/80); 34// Self.imageView.transform = Cgaffinetransformmakescale (scale, scale);//}36 PNS CGFloat scale = 1-(offs ETY/20); (scale >= 1)? scale:1;39 self.imageView.transform = Cgaffinetransformmakescale (scale, scale);}41 @end

Hover of internal controls in ScrollView

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.