scrollToTop无法在iPhone上运行,但它可以在iPad上运行

edr*_*c_s 6 iphone objective-c uiscrollview

我有两个视图控制器.一个页面控制滚动视图和一个细节滚动视图(滚动垂直).

当我点击iPhone上的状态栏时,scrollToTop无效,而在iPad中,scrollToTop正在工作.

我确信scrollView.scrollToTop是YES.因为我已经打印出来了.

有谁知道是什么导致iPhone scrollToTop无法正常工作?

谢谢

编辑:我尝试通过调用scrollView委托.在iPad中,这个委托给它打电话. - (BOOL)scrollViewShouldScrollToTop:(UIScrollView*)scrollView

在iPhone中它没有被调用.我已经使用了contentScrollView.delegate = self; 但是iPhone无法正常工作:(

编辑:尝试子类化UIWindow(不工作)

在window.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface Window : UIWindow
@end
Run Code Online (Sandbox Code Playgroud)

Window.m

 #import "Window.h"

 @implementation Window

 - (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if ([event type] == UIEventTypeTouches && point.y < 250) {
    //Send Your Notification Here
    NSLog(@"KAROOO");
}
NSLog(@"HELLOWW");
return [super hitTest:point withEvent:event];
}
@end
Run Code Online (Sandbox Code Playgroud)

AppDelegate.h

@property (nonatomic, strong) IBOutlet Window *window;
Run Code Online (Sandbox Code Playgroud)

AppDelegate.m

@synthesize window = _window;
Run Code Online (Sandbox Code Playgroud)

NSI*_*Max 3

据我了解,屏幕上同时有 2 个 UIScrollView。

根据我的所见和经验,在 iOS 4 上,并排有 2 个 UIScrollView 会产生未定义的行为。其中一个滚动视图可以滚动,有时其他滚动视图可以滚动,有时两者都不滚动。

在 iOS 5 上,如果您有 2 个并排的 UIScrollView,则点击状态栏“滚动到顶部”,UIScrollView 右侧“在您的点击下”

我不知道这是如何运作的,但这是我的观察。iOS 5 很智能!

如果您的 UIScrollViews 高于其他视图,则行为可能未定义。我没查过。

希望这可以帮助。

如果您想让它正常工作,那么这里有一个可能的解决方案。

在 UIWindow 上子类化或添加一个类别,并添加手势识别器/或实现 hitTest,仅检测 Y < 20 等的点击,然后让它发送通知并在 viewController 中监听此通知,并以编程方式将 UIScrollView 滚动到顶部。

编辑

在 UIWindow 子类 (iPad) 中实现此功能

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    if ([event type] == UIEventTypeTouches && point.y < 20 && [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) {
        NSLog(@"Portrait");
    } else if ([event type] == UIEventTypeTouches && point.y > 1004 && [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown) {
        NSLog(@"PortraitUpsideDown");
    } else if ([event type] == UIEventTypeTouches && point.x < 20 && [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft) {
        NSLog(@"LandscapeLeft");
    } else if ([event type] == UIEventTypeTouches && point.x > 748 && [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
        NSLog(@"LandscapeRight");
    }
    return [super hitTest:point withEvent:event];
}
Run Code Online (Sandbox Code Playgroud)