2

当 UIScrollView 被下拉到某个点时,我试图触发一个动作。这就是我现在所拥有的:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.y == -100.0) {
        NSLog(@"Trigger");

        [scrollView setContentOffset:CGPointMake(0.0, -200.0) animated:YES];
    }
}

这种工作,直到我结束我的触摸事件,然后 UIScrollView 返回到它的原始位置。知道如何解决这个问题吗?

4

2 回答 2

0

检查范围而不是单个像素,因为 scrollView 不会逐像素回滚。添加检查如下 -

if (scrollView.contentOffset.y < -100.0 && scrollView.contentOffset.y > -110.0)
{
     //call your method
}
于 2013-01-14T03:05:25.630 回答
0

I could not find the source For scrolling and holding the position of scrollview here is the code.

For the view where you want to set the scrollview and hold do like this ..

Viewcontroller.h
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;//from interface builder @property (weak, nonatomic) IBOutlet UIView *contentView;//from interface

Finally the interface hierarchy should be like this view-->scrollView-->contentView-->view Contents viewController.m

-(void)viewDidLayoutSubviews

{

[super viewDidLayoutSubviews];

[self.scrollView layoutIfNeeded];

self.scrollView.contentSize = self.contentView.bounds.size;

}

//To dismiss the scrollView when return key pressed ..you can place this code anywhere where you want

  • (BOOL)textFieldShouldReturn:(UITextField *)textField {

    self.scrollView.contentSize = self.view.frame.size;

    return YES;

}

For more info check this..http://spin.atomicobject.com/2014/03/05/uiscrollview-autolayout-ios/ I hope this helps someone..

于 2015-04-17T07:17:53.080 回答