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

是否可以將固定內容添加到 UIScrollView?

Is it possible to add fixed content to a UIScrollView?(是否可以將固定內容添加到 UIScrollView?)
本文介紹了是否可以將固定內容添加到 UIScrollView?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想創建一個 UITableViewUIScrollView 的子類,當內容偏移量大于 0 時,它會在頂部有一些陰影,表示內容是可滾動的.(見附圖)

I want to create a subclass of UITableView or UIScrollView that will have some shading at the top when the content offset is > 0 to indicate that the content is scrollable. (See image attached)

我現在實現它的方式是使用 UIViewController,它是 tableView 的委托.我只是在 tableView 頂部有一個 GradientView,然后截取 scrollViewDidScroll: 以動畫化頂部漸變的可見性.

The way I'm implementing it right now is using the UIViewController that is the delegate of the tableView. I simply have a GradientView on top of the tableView, and I intercept scrollViewDidScroll: to animate the visibility of that top gradient.

我對這個實現的問題是它不是干凈的".我希望我的 UIViewControllers 處理邏輯,而不是處理應用漸變和其他東西.我希望我可以刪除一個 UITableView 的子類,它會為我做到這一點.

My problem with this implementation is that it's not "clean". I want my UIViewControllers to take care of logic, and not to deal with applying gradients and stuff. I wish I could just drop a subclass of UITableView that will do that for me.

我面臨的挑戰是我無法弄清楚 tableView 如何在可滾動內容之上添加一個固定內容.

The challenge for me is that I can't figure out how the tableView could add to itself a fixed content on top of the scrollable content.

另一個問題是我應該重寫 UIScrollView 的什么方法來攔截滾動事件.顯然我不希望 tableView 成為自己的代表......

Another question is what method/s of UIScrollView should I override to intercept the scrolling event. Obviously I don't want the tableView to be the delegate of itself...

有什么想法嗎?

謝謝!

推薦答案

好的,我在 Apple 的 WWDC 2011 Session 104 video - Advanced Scroll View Techniques 中找到了解決方案.

Ok, so I found the solution on Apple's WWDC 2011 Session 104 video - Advanced Scroll View Techniques.

此視頻中有一個完整的部分是關于滾動視圖中的固定視圖".根據 Apple 的說法,這里的方法是覆蓋 layoutSubviews 并將所有代碼放在那里以放置您想要的任何位置 - 任何您想要的位置.

There is a whole section in this video about "Stationary Views" inside a scroll view. According to Apple, the way to go here is to override layoutSubviews and put there all the code to position whatever you want - wherever you want.

我試過了,它實際上很簡單,并且按預期工作.

I tried it and it's actually pretty easy and it's working as expected.

例如,如果我想在滾動內容時在表格頂部有一個陰影標題,這就是我應該編寫的代碼:

So for example if I would like a shadowed header on top of the table when the content is being scrolled, this is the code I should write:

-(void) layoutSubviews
{
    [super layoutSubviews];
    [self positionTopShadow];
}

-(void) positionTopShadow
{
    CGFloat yOffset = self.contentOffset.y;
    // I'm doing some limiting so that the maximum height of the shadow view will be 40 pixels
    yOffset = MIN(yOffset, 40);
    yOffset = MAX(0, yOffset);

    CGRect frame = self.topShadowView.frame;
    // The origin should be exactly like the content offset so it would look like
    // the shadow is at the top of the table (when it's actually just part of the content) 
    frame.origin = CGPointMake(0, self.contentOffset.y);
    frame.size.height = yOffset;
    frame.size.width = self.frame.size.width;
    self.topShadowView.frame = frame;

    if (self.topShadowView.superview == nil)
    {
        [self addSubview:self.topShadowView];
    }
    [self bringSubviewToFront:self.topShadowView];
}

這篇關于是否可以將固定內容添加到 UIScrollView?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的邊緣工作) - IT屋-程序員軟件開發技術分享社
ImageView Scaling when scrolling down(向下滾動時 ImageView 縮放)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的邊界自動更改,帶有內容插圖)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干擾按鈕.怎么修?)
Handling scroll views with (custom, interactive) view controller presentation and dismissal(使用(自定義、交互式)視圖控制器呈現和解除處理滾動視圖)
主站蜘蛛池模板: 久久久久国产一区二区 | 欧美高清性xxxxhdvideosex | 久久人人爽人人爽人人片av免费 | 日韩精品一区二区三区在线播放 | 亚洲一区二区三区在线视频 | 国产农村妇女毛片精品久久麻豆 | 免费视频久久 | 久在线视频播放免费视频 | 欧美一级大片免费观看 | 久久久五月天 | 日韩欧美国产一区二区 | 久草在线| 久久久久国产一区二区三区 | 精品www | 欧美在线a| 成人在线不卡 | 日日摸日日添日日躁av | 日本精品在线一区 | 亚洲一区二区在线播放 | 午夜免费成人 | 喷水毛片 | 成人国内精品久久久久一区 | 亚洲精品一区二区三区四区高清 | 99国产在线 | 国产一级片在线播放 | 日本成人福利视频 | 国产成人免费视频网站视频社区 | 一区二区在线不卡 | 久久久久久亚洲精品 | 成人国产精品久久久 | 成人在线观看免费 | 国产日韩电影 | 精品av天堂毛片久久久借种 | 国产精品视频一二三区 | 成人在线播放 | 欧美一区二区三区 | 日韩视频精品在线 | 国产精品1区| 久久av网 | 国产在线精品一区二区三区 | 久久亚洲视频 |