久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 UIScrollView 用兩根手指滾動

Scrolling with two fingers with a UIScrollView(使用 UIScrollView 用兩根手指滾動)
本文介紹了使用 UIScrollView 用兩根手指滾動的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個應用程序,我的主視圖同時接受 touchesBegantouchesMoved,因此接受單指觸摸和拖動.我想實現一個 UIScrollView,我讓它工作,但它覆蓋了拖動,因此我的 contentView 永遠不會收到它們.我想實現一個 UIScrollview,其中兩指拖動表示滾動,而單指拖動事件會傳遞給我的內容視圖,因此它可以正常執行.我需要創建自己的 UIScrollView 子類嗎?

I have an app where my main view accepts both touchesBegan and touchesMoved, and therefore takes in single finger touches, and drags. I want to implement a UIScrollView, and I have it working, but it overrides the drags, and therefore my contentView never receives them. I'd like to implement a UIScrollview, where a two finger drag indicates a scroll, and a one finger drag event gets passed to my content view, so it performs normally. Do I need create my own subclass of UIScrollView?

這是我實現 UIScrollViewappDelegate 中的代碼.

Here's my code from my appDelegate where I implement the UIScrollView.

@implementation MusicGridAppDelegate

@synthesize window;
@synthesize viewController;
@synthesize scrollView;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after app launch    
    //[application setStatusBarHidden:YES animated:NO];
    //[window addSubview:viewController.view];

    scrollView.contentSize = CGSizeMake(720, 480);
    scrollView.showsHorizontalScrollIndicator = YES;
    scrollView.showsVerticalScrollIndicator = YES;
    scrollView.delegate = self;
    [scrollView addSubview:viewController.view];
    [window makeKeyAndVisible];
}


- (void)dealloc {
    [viewController release];
    [scrollView release];
    [window release];
    [super dealloc];
}

推薦答案

你需要繼承 UIScrollView(當然!).然后你需要:

You need to subclass UIScrollView (of course!). Then you need to:

  • 制作單指事件以轉到您的內容視圖(簡單),并且

  • make single-finger events to go to your content view (easy), and

讓兩指事件滾動滾動視圖(可能容易,可能很難,可能不可能).

make two-finger events scroll the scroll view (may be easy, may be hard, may be impossible).

Patrick 的建議通常很好:讓您的 UIScrollView 子類了解您的內容視圖,然后在觸摸事件處理程序中檢查手指的數量并相應地轉發事件.只需確保 (1) 您發送到內容視圖的事件不會通過響應者鏈返回到 UIScrollView(即確保處理所有事件),(2) 尊重通常的觸摸事件流(即 touchesBegan,而不是一些 {touchesBegan, touchesMoved, touchesEnded},以 touchesEnded 或 touchesCancelled 結束),尤其是在處理 UIScrollView 時.#2 可能很棘手.

Patrick's suggestion is generally fine: let your UIScrollView subclass know about your content view, then in touch event handlers check the number of fingers and forward the event accordingly. Just be sure that (1) the events you send to content view don't bubble back to UIScrollView through the responder chain (i.e. make sure to handle them all), (2) respect the usual flow of touch events (i.e. touchesBegan, than some number of {touchesBegan, touchesMoved, touchesEnded}, finished with touchesEnded or touchesCancelled), especially when dealing with UIScrollView. #2 can be tricky.

如果您決定事件是針對 UIScrollView,另一個技巧是讓 UIScrollView 相信您的兩指手勢實際上是單指手勢(因為 UIScrollView 不能用兩根手指滾動).嘗試只將一根手指的數據傳遞給 super(通過過濾 (NSSet *)touches 參數——注意它只包含更改的觸摸——并完全忽略錯誤手指的事件).

If you decide the event is for UIScrollView, another trick is to make UIScrollView believe your two-finger gesture is actually a one-finger gesture (because UIScrollView cannot be scrolled with two fingers). Try passing only the data for one finger to super (by filtering the (NSSet *)touches argument — note that it only contains the changed touches — and ignoring events for the wrong finger altogether).

如果這不起作用,你就有麻煩了.從理論上講,您可以嘗試通過創建一個看起來類似于 UITouch 的類來創建人工觸摸以提供給 UIScrollView.底層 C 代碼不檢查類型,因此將 (YourTouch *) 轉換為 (UITouch *) 可能會起作用,并且您將能夠欺騙 UIScrollView 處理實際上并沒有發生的觸摸.

If that does not work, you are in trouble. Theoretically you can try to create artificial touches to feed to UIScrollView by creating a class that looks similar to UITouch. Underlying C code does not check types, so maybe casting (YourTouch *) into (UITouch *) will work, and you will be able to trick UIScrollView into handling the touches that did not really happen.

您可能想閱讀 我關于高級 UIScrollView 技巧的文章(并完全看一些不相關的 UIScrollView 示例代碼在那里).

You probably want to read my article on advanced UIScrollView tricks (and see some totally unrelated UIScrollView sample code there).

當然,如果你不能讓它工作,總是可以選擇手動控制 UIScrollView 的移動,或者使用完全自定義編寫的滾動視圖.Three20 庫中有 TTScrollView 類;用戶感覺不好,但程序員感覺不錯.

Of course, if you can't get it to work, there's always an option of either controlling UIScrollView's movement manually, or use an entirely custom-written scroll view. There's TTScrollView class in Three20 library; it does not feel good to the user, but does feel good to programmer.

這篇關于使用 UIScrollView 用兩根手指滾動的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設置 contentOffset 觸發 scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動時暫停 NSTimer)
主站蜘蛛池模板: 国产精品99久久久久久宅男 | 欧美日韩在线综合 | 亚洲视频区 | 国产色爽| 神马久久久久久久久久 | 成人国产精品色哟哟 | av一级在线观看 | av资源在线看 | 免费黄色a视频 | 成人精品一区二区三区 | 欧美一级视频免费看 | 韩日一区二区 | 国产精品久久久久久 | 成人中文字幕在线观看 | 成人中文网 | 亚洲欧美日韩国产综合 | 成人在线观看欧美 | 我爱操 | 精品国产乱码久久久久久闺蜜 | 亚洲精品一区在线观看 | 在线天堂免费中文字幕视频 | 亚洲欧美中文日韩在线v日本 | av福利网站 | 91精品国产91久久综合桃花 | 五月激情婷婷网 | 久久99精品久久久久久 | 久久一区二区免费视频 | 网络毛片 | 黄色毛片免费视频 | 欧美激情一区二区三区 | 亚洲欧洲日本国产 | 欧美激情国产精品 | 亚洲一区国产精品 | 精品三级在线观看 | 亚洲精品视频在线看 | 国产精品亚洲精品日韩已方 | 丝袜美腿一区 | 日韩视频精品在线 | 在线欧美亚洲 | 国产成人一区二区三区 | 日韩成人在线播放 |