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

使用 UIScrollView 用兩根手指滾動

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

問題描述

我有一個應用程序,我的主視圖同時接受 touchesBegantouchesMoved,因此接受單指觸摸和拖動.我想實現(xiàn)一個 UIScrollView,我讓它工作,但它覆蓋了拖動,因此我的 contentView 永遠不會收到它們.我想實現(xiàn)一個 UIScrollview,其中兩指拖動表示滾動,而單指拖動事件會傳遞給我的內容視圖,因此它可以正常執(zhí)行.我需要創(chuàng)建自己的 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?

這是我實現(xiàn) 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 子類了解您的內容視圖,然后在觸摸事件處理程序中檢查手指的數(shù)量并相應地轉發(fā)事件.只需確保 (1) 您發(fā)送到內容視圖的事件不會通過響應者鏈返回到 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 不能用兩根手指滾動).嘗試只將一根手指的數(shù)據(jù)傳遞給 super(通過過濾 (NSSet *)touches 參數(shù)——注意它只包含更改的觸摸——并完全忽略錯誤手指的事件).

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).

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

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模板網!

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

相關文檔推薦

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 觸發(fā) 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)
主站蜘蛛池模板: 欧美日韩中文字幕在线 | 亚洲视频www | 四季久久免费一区二区三区四区 | 日韩毛片 | 国产激情一区二区三区 | 欧美一区二区三区大片 | 青青草免费在线视频 | 免费一级大片 | 欧美综合在线观看 | 337p日本欧洲亚洲大胆 | 一区二区三区国产精品 | 午夜成人免费视频 | 丝袜久久 | 久久伊人青青草 | 久久视频精品在线 | 草久久久| 欧美一区二区 | 狠狠干2020| 中文字幕色站 | 亚洲一区二区三 | 久久天天综合 | 久久久久一区 | 亚洲视频三区 | 国产精品区二区三区日本 | 日韩一区二区三区视频 | 欧美一级特黄aaa大片在线观看 | 麻豆视频国产在线观看 | 99热首页| 亚洲欧美综合精品另类天天更新 | 精品国产乱码久久久久久老虎 | 亚洲91精品 | 国产精品婷婷 | 日韩在线精品强乱中文字幕 | 久久综合久久久 | 亚洲精品视频一区 | 精品无码久久久久久国产 | 中文精品视频 | 午夜影院在线观看版 | 午夜欧美| 韩日av片| 久久久久久国产精品免费免费男同 |