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

使兩個 UIScrollViews 跟隨彼此滾動

Making two UIScrollViews follow each others scrolling(使兩個 UIScrollViews 跟隨彼此滾動)
本文介紹了使兩個 UIScrollViews 跟隨彼此滾動的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如何讓兩個滾動視圖跟隨彼此滾動?

How would I make two scroll views follow each others scrolling?

例如,我在屏幕左側有一個滾動視圖 (A),其內容可以上下滾動,但不能左右滾動.滾動視圖 B 匹配 A 的上下滾動,但也可以左右滾動.滾動視圖 A 始終在屏幕上.

For instance, I have a scroll view (A) on the left of a screen, whose contents can scroll up and down, but not left and right. Scroll view B matches the up and down of A, but can also scroll left and right. Scroll view A is always on the screen.

-----------------------------------------------------------
|             |                                           |
|             |                                           |
|             |                                           |
|     A       |                    B                      |
|             |                                           |
|    scrolls  |                                           |
|   up & down |              scrolls all directions       |
|             |                                           |
-----------------------------------------------------------

我將如何做到這一點,以便(任一視圖的)上下滾動也會使另一個視圖沿相同的上下方向滾動?還是有其他方法可以做到這一點?

How would I make it so the the up and down scrolling (of either view) also makes the other view scroll in the same up-down direction? Or is there another method to do this?

推薦答案

將滾動視圖 A 的委托設置為您的視圖控制器...然后...

Set the delegate of scroll view A to be your view controller... then have...

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  CGPoint offset = scrollViewB.contentOffset;
  offset.y = scrollViewA.contentOffset.y;
  [scrollViewB setContentOffset:offset];
}

如果您希望雙方互相關注,則為他們設置委托并使用...

If you want both to follow each other, then set delegate for both of them and use...

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  if([scrollView isEqual:scrollViewA]) {
    CGPoint offset = scrollViewB.contentOffset;
    offset.y = scrollViewA.contentOffset.y;
    [scrollViewB setContentOffset:offset];
  } else {
    CGPoint offset = scrollViewA.contentOffset;
    offset.y = scrollViewB.contentOffset.y;
    [scrollViewA setContentOffset:offset];
  }
}

上面可以重構為有一個方法,它接受兩個滾動視圖并匹配另一個.

The above can be refactored to have a method which takes in two scrollviews and matches one to the other.

- (void)matchScrollView:(UIScrollView *)first toScrollView:(UIScrollView *)second {
  CGPoint offset = first.contentOffset;
  offset.y = second.contentOffset.y;
  [first setContentOffset:offset];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  if([scrollView isEqual:scrollViewA]) {
    [self matchScrollView:scrollViewB toScrollView:scrollViewA];  
  } else {
    [self matchScrollView:scrollViewA toScrollView:scrollViewB];  
  }
}

Swift 3 版本:

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if scrollView == scrollViewA {
            self.synchronizeScrollView(scrollViewB, toScrollView: scrollViewA)
        }
        else if scrollView == scrollViewB {
            self.synchronizeScrollView(scrollViewA, toScrollView: scrollViewB)
        }
    }

    func synchronizeScrollView(_ scrollViewToScroll: UIScrollView, toScrollView scrolledView: UIScrollView) {
        var offset = scrollViewToScroll.contentOffset
        offset.y = scrolledView.contentOffset.y

        scrollViewToScroll.setContentOffset(offset, animated: false)
    }

這篇關于使兩個 UIScrollViews 跟隨彼此滾動的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

iOS - Using storyboard and autolayout to center the UIScrollView(iOS - 使用故事板和自動布局使 UIScrollView 居中)
get index or tag value from imageview tap gesture(從 imageview 點擊手勢獲取索引或標簽值)
UIScrollView not scrolling regardless of large contentSize(無論內容大小如何,UIScrollView 都不會滾動)
Clean autorotation transitions in a paging UIScrollView(清除分頁 UIScrollView 中的自動旋轉轉換)
UIScrollView zooming with Auto Layout(UIScrollView 使用自動布局縮放)
How to create an image from a UIView / UIScrollView(如何從 UIView/UIScrollView 創建圖像)
主站蜘蛛池模板: 中文字幕人成乱码在线观看 | 羞羞视频免费观看 | 日本人麻豆 | 全免一级毛片 | 范冰冰一级做a爰片久久毛片 | 久久久久国产 | 1000部精品久久久久久久久 | av免费网站在线观看 | 一区二区三区免费 | 中文字幕视频在线看 | 97国产爽爽爽久久久 | 国产精品久久久久久久岛一牛影视 | 午夜小电影 | www.中文字幕.com| 国产精品久久久久久久久久久久久 | 欧美色综合一区二区三区 | 久久久青草婷婷精品综合日韩 | 一级毛片免费 | 91在线视频播放 | 国产一区91精品张津瑜 | 欧美三级电影在线播放 | 亚洲一区二区三区观看 | 91视频中文 | 精品亚洲二区 | 国产精品99久久久久久动医院 | 中文字幕在线观看www | 91久久国产综合久久 | 亚洲欧美精品国产一级在线 | 亚洲第一在线 | 色黄视频在线 | 精品av| 一区二区不卡视频 | 欧美黄 片免费观看 | 日本一区二区三区在线观看 | 日韩精品免费视频 | 91国内在线观看 | 天天看片天天干 | 国产a级毛毛片 | 精品国产伦一区二区三区观看方式 | 欧美一级二级视频 | 国产日韩欧美 |