問題描述
我有兩個視圖控制器.一個用于頁面控制的滾動視圖和一個用于詳細信息的滾動視圖(垂直滾動).
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 上工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!