简体   繁体   English

UIScrollView失去触摸事件

[英]UIScrollView losing touch events

i have a scroll view in my application and i want that when the user scrolls it down, so its contentOffset.y reaches -50, the scroll view will animate to the bottom of the screen (at this point the scrollview won't be visible). 我在我的应用程序中有一个滚动视图,我希望当用户向下滚动它时,使其contentOffset.y达到-50,滚动视图将动画到屏幕底部(此时,滚动视图将不可见)。

I managed to do this, but when i animate my scrollview back so it gets visible again it loses touch events and won't scroll anymore. 我设法做到了,但是当我为我的scrollview设置动画以使其再次可见时,它将失去触摸事件并且不再滚动。

i already tried to set scrollEnabled and userInteractionEnabled to YES but nothing works. 我已经尝试将scrollEnabled和userInteractionEnabled设置为YES,但没有任何效果。 If someone could help i would appreciate. 如果有人可以帮助我将不胜感激。

Thanks. 谢谢。

This is the code when i animate my scroll view to the bottom of the screen 这是我将滚动视图动画化到屏幕底部时的代码

[UIView animateWithDuration:0.5 animations:^
     {     
         CGRect scrollRect = self.scrollView.frame;
         CGRect newFrame = CGRectMake(scrollRect.origin.x, 367, scrollRect.size.width, self.scrollView.contentSize.height);
         self.scrollView.frame = newFrame;
     }
     completion:^(BOOL finished)
     {
         self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)] autorelease];
     }];

And this is the code where i make my scroll view visible again 这是我再次使滚动视图可见的代码

[UIView animateWithDuration:0.5 animations:^
 {
     CGRect scrollRect = self.scrollView.frame;
     CGRect newFrame = CGRectMake(scrollRect.origin.x, 0, scrollRect.size.width, self.scrollView.contentSize.height);
     self.scrollView.frame = newFrame;
 }
 completion:^(BOOL finished)
 {
     self.navigationItem.leftBarButtonItem = nil;
     self.scrollView.scrollEnabled = YES;
     self.scrollView.userInteractionEnabled = YES;
     _canScroll = YES;
 }];

and after that i can't scroll it anymore. 之后,我再也无法滚动它了。

您将滚动视图的高度设置为self.scrollView.contentSize.height,因此滚动视图将无法垂直滚动。请尝试将其更改为self.scrollview.frame.height

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM