2016-08-21 108 views

回答

0

试试这个代码:

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    UIView *maskView = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 100, 100)]; 
    maskView.backgroundColor = [UIColor greenColor]; 
    maskView.alpha = 0.5; 
    self.maskView = maskView; 
    [self.view addSubview:maskView]; 
} 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView { 
    CGRect rect = [self.label convertRect:CGRectMake(0, 0, 100, 100) toView:self.maskView]; 
    NSLog(@"%@", NSStringFromCGRect(rect)); 
    if (rect.origin.y >= self.maskView.frame.size.height || rect.origin.y <= -self.label.frame.size.height) { 
     self.label.backgroundColor = [UIColor redColor]; 
    } else { 
     self.label.backgroundColor = [UIColor orangeColor]; 
    } 
} 

的关键是scrollViewDidScroll:convertRect: toView:

enter image description here

enter image description here