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

使用 UIScrollView 用兩根手指滾動(dòng)

Scrolling with two fingers with a UIScrollView(使用 UIScrollView 用兩根手指滾動(dòng))
本文介紹了使用 UIScrollView 用兩根手指滾動(dòng)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

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

這是我實(shí)現(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(當(dāng)然!).然后你需要:

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

  • 制作單指事件以轉(zhuǎn)到您的內(nèi)容視圖(簡(jiǎn)單),并且

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

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

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

Patrick 的建議通常很好:讓您的 UIScrollView 子類了解您的內(nèi)容視圖,然后在觸摸事件處理程序中檢查手指的數(shù)量并相應(yīng)地轉(zhuǎn)發(fā)事件.只需確保 (1) 您發(fā)送到內(nèi)容視圖的事件不會(huì)通過(guò)響應(yīng)者鏈返回到 UIScrollView(即確保處理所有事件),(2) 尊重通常的觸摸事件流(即 touchesBegan,而不是一些 {touchesBegan, touchesMoved, touchesEnded},以 touchesEnded 或 touchesCancelled 結(jié)束),尤其是在處理 UIScrollView 時(shí).#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.

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

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

如果這不起作用,你就有麻煩了.從理論上講,您可以嘗試通過(guò)創(chuàng)建一個(gè)看起來(lái)類似于 UITouch 的類來(lái)創(chuàng)建人工觸摸以提供給 UIScrollView.底層 C 代碼不檢查類型,因此將 (YourTouch *) 轉(zhuǎn)換為 (UITouch *) 可能會(huì)起作用,并且您將能夠欺騙 UIScrollView 處理實(shí)際上并沒(méi)有發(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.

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

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

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

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.

這篇關(guān)于使用 UIScrollView 用兩根手指滾動(dòng)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫(kù)中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設(shè)置 contentOffset 觸發(fā) scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁(yè)面之間的照片應(yīng)用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動(dòng)時(shí)暫停 NSTimer)
主站蜘蛛池模板: 青春草在线 | 久操福利 | 久久综合伊人 | 一级黄色淫片 | 综合久久综合久久 | 久久精品欧美一区二区三区麻豆 | 又黑又粗又长的欧美一区 | 婷婷色在线 | 九一在线 | 久久久亚洲精品视频 | 激情欧美一区二区三区中文字幕 | 国产伦精品一区二区 | 精品一区二区电影 | 日韩中文字幕在线视频 | 久久噜噜噜精品国产亚洲综合 | 狠狠的干| 日本三级网址 | 99色在线视频 | 日本久久久一区二区三区 | 精品中文字幕久久 | 欧美手机在线 | 91精品国产综合久久婷婷香蕉 | 2019中文字幕视频 | 中文字幕在线观看第一页 | 男人天堂午夜 | 亚洲国产精品久久久久 | 国产免费一二三区 | av一级毛片 | av在线播放网站 | 国产成人99久久亚洲综合精品 | 在线免费av观看 | 久久久久免费精品国产 | 国产精品久久久久久久久久久久久 | av网站推荐| 国产一区二区成人 | 成人伊人 | 久久久夜夜夜 | 精品国产综合 | 日韩欧美国产一区二区 | 亚洲第一天堂 | 国产精品久久久久久久久久免费 |