iPhone OS:删除/添加后,点按状态栏以滚动到顶部不起作用

时间:2022-12-06 17:20:41

Using this method to hide the status bar:

使用此方法隐藏状态栏:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];

When setting "hidden" back to NO, the tap-to-scroll-to-top (in UIWebView, UITableView, whatever) doesn't work any more, and requires a restart of the app to get the functionality back.

当将“隐藏”设置回NO时,点击滚动到顶部(在UIWebView,UITableView,无论如何)都不再起作用,并且需要重新启动应用程序才能恢复功能。

Is this a bug (I filed a rdar anyhow) or have I missed a step? Should I perhaps expect this behavior since the statusBar "loses touch" somehow with the respective view?

这是一个错误(无论如何我提交了一个rdar)或者我错过了一步?我是否应该期待这种行为,因为statusBar以某种方式与相应的视图“失去联系”?

9 个解决方案

#1


18  

You could try setting the ScrollsToTop property to true again after re-showing it:

重新显示后,您可以尝试再次将ScrollsToTop属性设置为true:

[currentView setScrollsToTop:YES];

If that's not working, are you definitely only showing one view? If there is more than one scrolling view a scrollViewDidScrollToTop message is ignored...

如果那不起作用,你肯定只展示一个视图吗?如果有多个滚动视图,则忽略scrollViewDidScrollToTop消息...

#2


10  

In iOS 5.0 you can access the scrollview property of the UIWebView

在iOS 5.0中,您可以访问UIWebView的scrollview属性

webView.scrollView.scrollsToTop = YES;

#3


7  

The following fix by Alex worked for me. Thanks!

Alex的以下修复工作对我有用。谢谢!

((UIScrollView *)[[webView subviews] objectAtIndex:0]).scrollsToTop = NO;

Being in a hurry this fix worked great, however given more time I might've subclassed the UIWebView and accessed the protected UIScrollView member directly.

匆忙这个修复工作很好,但是如果有更多的时间,我可能会将UIWebView子类化并直接访问受保护的UIScrollView成员。

The worry I have with Alex' method is that it assumes that UIScrollView is at index zero of the subviews (encapsulation allows private members to change). Which suggests another solution still:

我对Alex'方法的担心是它假设UIScrollView位于子视图的索引零处(封装允许私有成员更改)。这仍然表明另一种解决方案

for (UIView* v in [webView subviews])
{
    if ([v isKindOfClass:[UIScrollView class]])
    {
        (UIScrollView *)v.scrollsToTop = NO;
    }
}

#4


5  

I was having a similar problem where the scroll-to-top functionality was lost. Turns out this will only work when you have only one active view at a time (within the same scroll view). In my case I had a table view and another view which would fade in/out. Adding a removeFromSuperview at the end of the animation did the trick.

我遇到了类似的问题,滚动到顶部的功能丢失了。事实证明,只有当你一次只有一个活动视图时(在同一个滚动视图中),这才会起作用。在我的情况下,我有一个表视图和另一个淡入/淡出的视图。在动画结束时添加removeFromSuperview就可以了。

The answer was in the UIScrollView.h file comments:

答案是在UIScrollView.h文件中注释:

/*
 this is for the scroll to top gesture. by default, a single scroll visible scroll view with this flag set will get the call. if there is more than one visible with this
 flag set or the delegeat method returns NO, the view isn't scrolled 
 */
@property(nonatomic) BOOL  scrollsToTop;          // default is YES. if set, special gesture will scroll to top of view after consulting delegate

#5


5  

You can use the following code to have the UIWebView ignore scrollToTop without the extra UIScrollView:

您可以使用以下代码让UIWebView忽略scrollToTop,而无需额外的UIScrollView:

((UIScrollView *)[[webView valueForKey:@"_internal"] valueForKey:@"scroller"]).scrollsToTop = NO;

#6


3  

I had a similar problem after playing a Youtube video within my app. scrollsToTop was still set to YES but tapping the status bar had no effect.

在我的应用中播放Youtube视频后,我遇到了类似的问题。 scrollsToTop仍设置为YES,但点击状态栏无效。

I finally realised that my app window was no longer the key window. After adding the following line to a UIWindow subclass (which I already had for other reasons) everything worked as it should again:

我终于意识到我的应用程序窗口不再是关键窗口。将以下行添加到UIWindow子类(我已经出于其他原因)之后,所有内容都应该再次运行:

if (![self isKeyWindow]) [self makeKeyWindow];

#7


0  

I just ran across a similar behavior in the app I'm currently working on. In its case, if you load a YouTube video from within a UIWebView, scroll to top stops working for the rest of the application's life cycle. I kind of assume this might happen after loading the movie player as well, but haven't confirmed. That functionality has been around a lot longer and probably has fewer bugs.

我刚刚在我正在处理的应用程序中遇到过类似的行为。在这种情况下,如果您从UIWebView中加载YouTube视频,请滚动到顶部停止,以便在应用程序的其余生命周期中工作。我有点假设这可能在加载电影播放器​​后发生,但尚未确认。该功能已经存在了很长时间,并且可能具有更少的错误。

#8


0  

When there are multiple scrollview, you can also set scrollUpToTop to NO for the others scrollview. cf:

当存在多个scrollview时,您还可以将scrollUpToTop设置为NO以用于其他scrollview。 CF:

setScrollsToTop with multiple UIScrollView classes and/or subclasses(UITableView)

具有多个UIScrollView类和/或子类的setScrollsToTop(UITableView)

#9


0  

I want to add my case, I add an UIWebView on an UIScrollView, as h4xxr had answered on the top:

我想添加我的案例,我在UIScrollView上添加一个UIWebView,因为h4xxr在顶部回答:

If there is more than one scrolling view a scrollViewDidScrollToTop message is ignored

如果有多个滚动视图,则忽略scrollViewDidScrollToTop消息

So, I get a simply way to make it work on webView: just set the scrollView·s scrollsToTop property false.

所以,我得到一个简单的方法使它在webView上工作:只需将scrollView的s scrollsToTop属性设置为false。

And when tap the status bar, it won`t got intercepted by the scrollView, and the webView scrolls to the top!

当点击状态栏时,它不会被scrollView截获,并且webView会滚动到顶部!

    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.frame = self.view.bounds;
    scrollView.scrollsToTop = false; //igore scrollView`s scrollsToTop
    [self.view addSubview:scrollView];

    UIWebView *webView = [[UIWebView alloc] init];
    webView.frame = scrollView.bounds;
    [scrollView addSubview:webView];

#1


18  

You could try setting the ScrollsToTop property to true again after re-showing it:

重新显示后,您可以尝试再次将ScrollsToTop属性设置为true:

[currentView setScrollsToTop:YES];

If that's not working, are you definitely only showing one view? If there is more than one scrolling view a scrollViewDidScrollToTop message is ignored...

如果那不起作用,你肯定只展示一个视图吗?如果有多个滚动视图,则忽略scrollViewDidScrollToTop消息...

#2


10  

In iOS 5.0 you can access the scrollview property of the UIWebView

在iOS 5.0中,您可以访问UIWebView的scrollview属性

webView.scrollView.scrollsToTop = YES;

#3


7  

The following fix by Alex worked for me. Thanks!

Alex的以下修复工作对我有用。谢谢!

((UIScrollView *)[[webView subviews] objectAtIndex:0]).scrollsToTop = NO;

Being in a hurry this fix worked great, however given more time I might've subclassed the UIWebView and accessed the protected UIScrollView member directly.

匆忙这个修复工作很好,但是如果有更多的时间,我可能会将UIWebView子类化并直接访问受保护的UIScrollView成员。

The worry I have with Alex' method is that it assumes that UIScrollView is at index zero of the subviews (encapsulation allows private members to change). Which suggests another solution still:

我对Alex'方法的担心是它假设UIScrollView位于子视图的索引零处(封装允许私有成员更改)。这仍然表明另一种解决方案

for (UIView* v in [webView subviews])
{
    if ([v isKindOfClass:[UIScrollView class]])
    {
        (UIScrollView *)v.scrollsToTop = NO;
    }
}

#4


5  

I was having a similar problem where the scroll-to-top functionality was lost. Turns out this will only work when you have only one active view at a time (within the same scroll view). In my case I had a table view and another view which would fade in/out. Adding a removeFromSuperview at the end of the animation did the trick.

我遇到了类似的问题,滚动到顶部的功能丢失了。事实证明,只有当你一次只有一个活动视图时(在同一个滚动视图中),这才会起作用。在我的情况下,我有一个表视图和另一个淡入/淡出的视图。在动画结束时添加removeFromSuperview就可以了。

The answer was in the UIScrollView.h file comments:

答案是在UIScrollView.h文件中注释:

/*
 this is for the scroll to top gesture. by default, a single scroll visible scroll view with this flag set will get the call. if there is more than one visible with this
 flag set or the delegeat method returns NO, the view isn't scrolled 
 */
@property(nonatomic) BOOL  scrollsToTop;          // default is YES. if set, special gesture will scroll to top of view after consulting delegate

#5


5  

You can use the following code to have the UIWebView ignore scrollToTop without the extra UIScrollView:

您可以使用以下代码让UIWebView忽略scrollToTop,而无需额外的UIScrollView:

((UIScrollView *)[[webView valueForKey:@"_internal"] valueForKey:@"scroller"]).scrollsToTop = NO;

#6


3  

I had a similar problem after playing a Youtube video within my app. scrollsToTop was still set to YES but tapping the status bar had no effect.

在我的应用中播放Youtube视频后,我遇到了类似的问题。 scrollsToTop仍设置为YES,但点击状态栏无效。

I finally realised that my app window was no longer the key window. After adding the following line to a UIWindow subclass (which I already had for other reasons) everything worked as it should again:

我终于意识到我的应用程序窗口不再是关键窗口。将以下行添加到UIWindow子类(我已经出于其他原因)之后,所有内容都应该再次运行:

if (![self isKeyWindow]) [self makeKeyWindow];

#7


0  

I just ran across a similar behavior in the app I'm currently working on. In its case, if you load a YouTube video from within a UIWebView, scroll to top stops working for the rest of the application's life cycle. I kind of assume this might happen after loading the movie player as well, but haven't confirmed. That functionality has been around a lot longer and probably has fewer bugs.

我刚刚在我正在处理的应用程序中遇到过类似的行为。在这种情况下,如果您从UIWebView中加载YouTube视频,请滚动到顶部停止,以便在应用程序的其余生命周期中工作。我有点假设这可能在加载电影播放器​​后发生,但尚未确认。该功能已经存在了很长时间,并且可能具有更少的错误。

#8


0  

When there are multiple scrollview, you can also set scrollUpToTop to NO for the others scrollview. cf:

当存在多个scrollview时,您还可以将scrollUpToTop设置为NO以用于其他scrollview。 CF:

setScrollsToTop with multiple UIScrollView classes and/or subclasses(UITableView)

具有多个UIScrollView类和/或子类的setScrollsToTop(UITableView)

#9


0  

I want to add my case, I add an UIWebView on an UIScrollView, as h4xxr had answered on the top:

我想添加我的案例,我在UIScrollView上添加一个UIWebView,因为h4xxr在顶部回答:

If there is more than one scrolling view a scrollViewDidScrollToTop message is ignored

如果有多个滚动视图,则忽略scrollViewDidScrollToTop消息

So, I get a simply way to make it work on webView: just set the scrollView·s scrollsToTop property false.

所以,我得到一个简单的方法使它在webView上工作:只需将scrollView的s scrollsToTop属性设置为false。

And when tap the status bar, it won`t got intercepted by the scrollView, and the webView scrolls to the top!

当点击状态栏时,它不会被scrollView截获,并且webView会滚动到顶部!

    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.frame = self.view.bounds;
    scrollView.scrollsToTop = false; //igore scrollView`s scrollsToTop
    [self.view addSubview:scrollView];

    UIWebView *webView = [[UIWebView alloc] init];
    webView.frame = scrollView.bounds;
    [scrollView addSubview:webView];