scrollToTop is not working on iPhone but it is working on iPad(scrollToTop 在 iPhone 上不工作,但在 iPad 上工作)
问题描述
我有两个视图控制器.一个用于页面控制的滚动视图和一个用于详细信息的滚动视图(垂直滚动).
I have two view controller. One scrollview for page control and one for detail (scroll vertical).
当我在 iPhone 上单击状态栏时,scrollToTop 不起作用,而在 iPad 中,scrollToTop 正在工作.
When i click status bar on iPhone the scrollToTop not working, and in iPad the scrollToTop is working.
我确定 scrollView.scrollToTop 是 YES.因为我已经打印出来了.
I am sure that the scrollView.scrollToTop is YES. because i already print it.
谁知道是什么原因导致 iPhone 的 scrollToTop 不工作?
Anyone know what cause the iPhone scrollToTop not working?
谢谢
我尝试调用 scrollView 委托.在 iPad 中,这个委托被称为.- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
I try by calling the scrollView delegate. in iPad this delegate its called. - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
在 iPhone 中它不被调用.我已经同时使用了contentScrollView.delegate = self;但是iphone不工作:(
in iPhone it is not called. I already use both contentScrollView.delegate = self; But the iphone not working :(
尝试子类化 UIWindow(不工作)
Try subclassing UIWindow (not working)
窗口.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface Window : UIWindow
@end
窗口.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
AppDelegate.h
@property (nonatomic, strong) IBOutlet Window *window;
AppDelegate.m
AppDelegate.m
@synthesize window = _window;
推荐答案
据我了解,您的屏幕上同时有 2 个 UIScrollView.
From what I understand you have 2 UIScrollViews simultaneously on screen.
据我所见&有经验的,在 iOS 4 上并排有 2 个 UIScrollView 会产生未定义的行为.其中一个滚动视图可能会滚动,有时可能会滚动,有时两者都不会.
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.
在 iOS 5 上,如果您并排有 2 个 UIScrollView,然后点击状态栏滚动到顶部"UIScrollView 右侧在您的点击下"
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"
我不知道这是如何工作的,但这是我的观察.iOS 5 很智能!!
I don't know how this works, but this has been my observation. iOS 5 is smart !!
如果您的 UIScrollViews 高于其他,则可能行为未定义.我没查过.
If your UIScrollViews are one above other then probably the behaviour is undefined. I haven't checked.
希望这会有所帮助.
如果你想让它正常工作,那么这里有一个可能的解决方案.
If you want to get it working anyways then here is a possible solution.
子类 或在 UIWindow 上添加一个类别并添加一个手势识别器/或实现仅检测 Y <的点击的 hitTest20 以此类推,然后让它发送通知并在您的 viewController 中收听,并以编程方式将 UIScrollView 滚动到顶部.
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.
编辑
在 UIWindow 子类 (iPad) 中实现它
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 上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:scrollToTop 在 iPhone 上不工作,但在 iPad 上工作
基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01