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

avo*_*ade 8 iphone cocoa-touch iphone-sdk-3.0

使用此方法隐藏状态栏:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
Run Code Online (Sandbox Code Playgroud)

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

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

h4x*_*xxr 18

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

[currentView setScrollsToTop:YES];
Run Code Online (Sandbox Code Playgroud)

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


Pau*_*per 10

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

webView.scrollView.scrollsToTop = YES;
Run Code Online (Sandbox Code Playgroud)


小智 7

The following fix by Alex worked for me. Thanks!

((UIScrollView *)[[webView subviews] objectAtIndex:0]).scrollsToTop = NO;
Run Code Online (Sandbox Code Playgroud)

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.

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:

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


Nic*_*lis 5

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

((UIScrollView *)[[webView valueForKey:@"_internal"] valueForKey:@"scroller"]).scrollsToTop = NO;
Run Code Online (Sandbox Code Playgroud)

  • 由于这使用私有API调用,这可能会导致您的应用程序被拒绝.你可以逃脱`((UIScrollView*)[[webView subviews] objectAtIndex:0]).scrollsToTop = NO;` (4认同)

Jua*_*uan 5

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

答案在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
Run Code Online (Sandbox Code Playgroud)