简体   繁体   中英

How can I do this with UIScrollView?

I want the effect like this:

在此处输入图片说明 在此处输入图片说明

When I scroll the word from "image1" to "image2" then the background also change, I just don't know how to set the word detection(the line).

@interface myViewController : UIViewController<UIScrollViewDelegate>
@end
- (void)viewDidLoad
{
    [super viewDidLoad];
    UIScrollView *myscrollView=[[UIScrollView alloc] initWithFrame: CGRectMake(0,0,320,460)];
    myscrollView.delegate = self;
    CGPoint position = CGPointMake(100, 150);
    [myscrollView setContentOffset:position animated:YES];
 }
-(void) scrollViewDidScroll:(UIScrollView *) scrollView{
}

-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
}

Use the scrollViewDidScroll method, and inside call yourScrollView.contentOffset to check how much you scrolled; then make the necessary changes.

Another way, is by checking if the frame of the scrollView intersects the frame of the label, using CGRect 's intersects function inside of scrollViewDidScroll . This might be the easier one.

Check the documentation for scrollViewDidScroll if you need more info.

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