scrollToTop无法在iPhone上运行,但它可以在iPad上运行 [英] scrollToTop is not working on iPhone but it is working on iPad

查看:196
本文介绍了scrollToTop无法在iPhone上运行,但它可以在iPad上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

我确定scrollView.scrollToTop为YES。因为我已打印出来了。



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



谢谢

p>

编辑:
我尝试调用scrollView委托。 iPad中的
这个委托叫它。
- (BOOL)scrollViewShouldScrollToTop :( UIScrollView *)scrollView



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



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



Window.h

  #import< UIKit / UIKit.h> 
#import< Foundation / Foundation.h> ;
@interface窗口:UIWindow
@end

Window.m

  #importWindow.h

@implementation窗口

- ( UIView *)hitTest:(CGPoint)指向withEvent:(UIEvent *)事件{
if([event type] == UIEventTypeTouches&& point.y< 250){
//发送你的通知在这里
NSLog(@KAROOO);
}
NSLog(@HELLOWW);
返回[super hitTest:指向withEvent:event];
}
@end

AppDelegate.h

  @property(非原子,强)IBOutlet窗口*窗口; 

AppDelegate.m

  @synthesize window = _window; 


解决。案

据我了解,你同时有2个UIScrollViews在屏幕上



这是我所看到的和放;经验丰富,
在iOS 4上有2个UIScrollViews并排给出了未定义的行为。其中一个scrollview可以滚动,有时也可以滚动,有时也不滚动。



在iOS 5上,如果你有2个UIScrollView并排,那么点击状态栏滚动到顶部 UIScrollView正确在您的点击下



我不知道这是如何工作的,但这是我的观察。 iOS 5很聪明!!



如果您的UIScrollViews高于其他,那么可能行为未定义。我没有检查过。



希望这会有所帮助。



如果你想让它继续工作那么这里是一种可能的解决方案。



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



编辑



在UIWindow子类(iPad)中实现它

   - (UIView *)hitTest:(CGPoint)指向withEvent:(UIEvent *)事件{
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 );
}否则if([event type] == UIEventTypeTouches&& point.x< 20&& [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft){
NSLog(@LandscapeLeft );
}否则if([event type] == UIEventTypeTouches&& point.x> 748&& [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight){
NSLog(@LandscapeRight );
}
return [super hitTest:point withEvent:event];
}


I have two view controller. One scrollview for page control and one for detail (scroll vertical).

When i click status bar on iPhone the scrollToTop not working, and in iPad the scrollToTop is working.

I am sure that the scrollView.scrollToTop is YES. because i already print it.

Anyone know what cause the iPhone scrollToTop not working?

Thank you

Edit: I try by calling the scrollView delegate. in iPad this delegate its called. - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView

in iPhone it is not called. I already use both contentScrollView.delegate = self; But the iphone not working :(

Edit: Try subclassing UIWindow (not working)

Window.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface Window : UIWindow
@end

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

AppDelegate.h

@property (nonatomic, strong) IBOutlet Window *window;

AppDelegate.m

@synthesize window = _window;

解决方案

From what I understand you have 2 UIScrollViews simultaneously on screen.

From what I have seen & experienced, On iOS 4 having 2 UIScrollViews side by side gives undefined behaviour. One of the scrollview may scroll, sometimes other, sometimes neither.

On iOS 5 if you have 2 UIScrollViews side by side then tapping on status bar "scrolls to top" the UIScrollView right "under your tap"

I don't know how this works, but this has been my observation. iOS 5 is smart !!

If your UIScrollViews are one above other then probably the behaviour is undefined. I haven't checked.

Hope this helps.

If you want to get it working anyways then here is a possible solution.

Subclass or Add a category on UIWindow and add a gesture recognizer / or implement hitTest that detects tap only for Y < 20 and so on and then have it send a notification and listen to this in your viewController and programmatically scroll the UIScrollView to top.

EDIT

Implement this in the UIWindow subclass (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];
}

这篇关于scrollToTop无法在iPhone上运行,但它可以在iPad上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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