下拉 UIScrollView 并保持 y 位置 [英] Pull down UIScrollView and hold y position

查看:61
本文介绍了下拉 UIScrollView 并保持 y 位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to fire an action when UIScrollView is pulled down to a certain point. This is what I have right now:

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

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

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

This kind of works, until I end my touch event and then UIScrollView returns to it's original position. Any idea how to solve this?

推荐答案

我找不到源代码滚动和保持scrollview的位置在这里是代码.

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 ..

视图控制器.h
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;//来自界面构建器@property (weak, nonatomic) IBOutlet UIView *contentView;//来自接口

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

最后界面层次应该是这样的查看-->scrollView-->contentView-->查看内容视图控制器.m

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;

}

//按下回车键时关闭scrollView..你可以把这段代码放在你想要的任何地方

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

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

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

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

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

返回YES;

}

有关更多信息,请查看此..http://spin.atomicobject.com/2014/03/05/uiscrollview-autolayout-ios/我希望这对某人有所帮助..

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

这篇关于下拉 UIScrollView 并保持 y 位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆