我工作的一個項目,需要創建一個類似iPhone的主屏幕畫面的畫面:創建像iPhone主屏幕滾動型帶和按鈕
- 多頁
- A A滾動視圖一堆圖標
- 如果沒有在編輯模式下,通過不同的頁面刷卡(即使我開始上的圖標觸摸)
- 如果沒有在編輯模式下,點擊圖標做一些事情
- 在編輯模式下,拖交換圖標地方,甚至交換到不同的網頁
- 在編輯模式下,點擊圖標刪除它
以前我從幾個論壇,我要繼承的UIScrollView,以有對UIViews觸摸輸入讀取它的頂部。所以,我是子類重寫的方法來處理觸摸:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//If not dragging, send event to next responder
if (!self.dragging)
[self.nextResponder touchesBegan:touches withEvent:event];
else
[super touchesBegan:touches withEvent:event];
}
總的來說,我已經覆蓋的touchesBegan :, touchesMoved:和touchesEnded:方法與此類似。
然後在視圖控制器,I加入到下面的代碼:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
UIView *hitView = (UIView *)touch.view;
if ([hitView isKindOfClass:[UIView class]]) {
[hitView doSomething];
NSLog(@"touchesBegan");
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
// Some codes to move the icons
NSLog(@"touchesMoved");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touchesEnded");
}
當運行該應用程序,我有方法的touchesBegan正確檢測。但是,當我試圖拖動圖標時,圖標剛剛移動了一點點,然後頁面開始滾動。在控制檯中,它僅記錄2或3個「touchesMoved」消息。但是,我從另一個項目中瞭解到,只要我還在屏幕上拖動,它應該記錄大量的「touchesMoved」消息。
(我懷疑我有delayedContentTouches設置爲YES,所以當我試圖拖動圖標時會稍微延遲一段時間後,它會發送信號返回到滾動視圖以滾動頁面。請糾正我,如果我錯了。)
所以,如果任何幫助的代碼來執行上述任務將不勝感激。我在這個地方呆了近一個星期,沒有任何希望。非常感謝。
而不是試圖推出自己的實現,有你從Three20項目看TTLauncherView:http://github.com/facebook/three20/blob/master/src/TTLauncherView.m?它可能已經這樣做了。 – 2010-03-18 12:35:03
這個問題的重複:http://stackoverflow.com/questions/4969263/create-springboard-like-main-view(反之亦然)。 – livingtech 2011-08-16 21:39:28