代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C#
】
osx 下拉刷新
作者:
DsonKing
/ 发布于
2016/1/11
/
637
?using System; using UIKit; using CoreAnimation; using Foundation; namespace ScrollRefreshView { public enum EGOPullRefreshState:int { EGOOPullRefreshPulling = 0, EGOOPullRefreshNormal, EGOOPullRefreshLoading, }; public interface IEGORefreshTableHeaderDelegate { void EGORefreshTableHeaderDidTriggerRefresh(EGORefreshTableHeaderView view); bool EGORefreshTableHeaderDataSourceIsLoading(EGORefreshTableHeaderView view); NSDate EGORefreshTableHeaderDataSourceLastUpdated(EGORefreshTableHeaderView view); } public class EGORefreshTableHeaderView:UIView { #region Field private IEGORefreshTableHeaderDelegate _delegate; private EGOPullRefreshState _state; private UILabel _lastUpdatedLabel; private UILabel _statusLabel; private CALayer _arrowImage; private UIActivityIndicatorView _activityView; #endregion #region Property public IEGORefreshTableHeaderDelegate Delegate { get { return _delegate; } set { _delegate = value; } } #endregion #region Construct public EGORefreshTableHeaderView(CoreGraphics.CGRect frame):base(frame) { AutoresizingMask = UIViewAutoresizing.FlexibleWidth; BackgroundColor = UIColor.FromRGBA((nfloat)(226.0/255.0),(nfloat)(231.0/255.0),(nfloat)(237.0/255.0),(nfloat)(1.0)); UILabel label = new UILabel(new CoreGraphics.CGRect(0.0f, frame.Size.Height - 30.0f, frame.Size.Width, 20.0f)); label.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; label.Font =UIFont.SystemFontOfSize(12.0f); label.TextColor=UIColor.FromRGBA((nfloat)(87.0/255.0),(nfloat)(108.0/255.0),(nfloat)(137.0/255.0),(nfloat)(1.0)); label.ShadowColor = UIColor.FromWhiteAlpha(0.9f,1.0f); label.ShadowOffset = new CoreGraphics.CGSize(0.0f,1.0f); base.AddSubview(label); _lastUpdatedLabel = label; label = new UILabel(new CoreGraphics.CGRect(0.0f, frame.Size.Height - 48.0f, frame.Size.Width, 20.0f)); label.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; label.Font =UIFont.SystemFontOfSize(13.0f); label.TextColor=UIColor.FromRGBA((nfloat)(87.0/255.0),(nfloat)(108.0/255.0),(nfloat)(137.0/255.0),(nfloat)(1.0)); label.ShadowColor = UIColor.FromWhiteAlpha(0.9f,1.0f); label.ShadowOffset = new CoreGraphics.CGSize(0.0f,1.0f); label.BackgroundColor = UIColor.Clear; label.TextAlignment = UITextAlignment.Center; base.AddSubview(label); _statusLabel=label; CALayer layer = CALayer.Create(); layer.Frame = new CoreGraphics.CGRect(25.0f, frame.Size.Height - 65.0f, 30.0f, 55.0f); layer.ContentsGravity="kCAGravityResizeAspect"; layer.Contents = UIImage.FromBundle("blueArrow").CGImage; if(UIScreen.MainScreen.RespondsToSelector(new ObjCRuntime.Selector("scale"))) { layer.ContentsScale = UIScreen.MainScreen.Scale; } base.Layer.AddSublayer(layer); _arrowImage = layer; UIActivityIndicatorView view = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.Gray); view.Frame = new CoreGraphics.CGRect(25.0f, frame.Size.Height - 38.0f, 20.0f, 20.0f); base.AddSubview(view); _activityView = view; SetState(EGOPullRefreshState.EGOOPullRefreshNormal); } #endregion #region Function public void RefreshLastUpdatedDate() { if (_delegate != null) { NSDate date = _delegate.EGORefreshTableHeaderDataSourceLastUpdated(this); NSDateFormatter formatter = new NSDateFormatter(); formatter.AMSymbol = "AM"; formatter.PMSymbol = "PM"; formatter.DateFormat = "MM/dd/yyyy hh:mm:a"; _lastUpdatedLabel.Text = string.Format("Last Updated:{0}", formatter.StringFor(date)); NSUserDefaults.StandardUserDefaults.SetValueForKey(new NSString(_lastUpdatedLabel.Text), new NSString("EGORefreshTableView_LastRefresh")); NSUserDefaults.StandardUserDefaults.Synchronize(); } else { _lastUpdatedLabel.Text = string.Empty; } } public void EGORefreshScrollViewDidScroll(UIScrollView scrollView) { if (_state == EGOPullRefreshState.EGOOPullRefreshLoading) { double offset=System.Math.Max(scrollView.ContentOffset.Y * -1,0); offset = System.Math.Min(offset, 60); scrollView.ContentInset = new UIEdgeInsets((nfloat)offset, 0.0f, 0.0f, 0.0f); } else if(scrollView.Dragging) { bool _loading = false; if (_delegate != null) { _loading = _delegate.EGORefreshTableHeaderDataSourceIsLoading(this); } if (_state == EGOPullRefreshState.EGOOPullRefreshPulling && scrollView.ContentOffset.Y > -65.0f && scrollView.ContentOffset.Y < 0.0f && !_loading) { SetState(EGOPullRefreshState.EGOOPullRefreshNormal); } else if (_state == EGOPullRefreshState.EGOOPullRefreshNormal && scrollView.ContentOffset.Y < -65.0f && !_loading) { SetState(EGOPullRefreshState.EGOOPullRefreshPulling); } if (scrollView.ContentInset.Top != 0) { scrollView.ContentInset = UIEdgeInsets.Zero; } } } public void EGORefreshScrollViewDidEndDragging(UIScrollView scrollView) { bool _loading = false; if (_delegate != null) { _loading = _delegate.EGORefreshTableHeaderDataSourceIsLoading(this); } if (scrollView.ContentOffset.Y <= -65.0f && !_loading) { if (_delegate != null) { _delegate.EGORefreshTableHeaderDidTriggerRefresh(this); } SetState(EGOPullRefreshState.EGOOPullRefreshLoading); UIView.BeginAnimations(null, IntPtr.Zero); UIView.SetAnimationDuration(0.2); scrollView.ContentInset = new UIEdgeInsets(60.0f, 0.0f, 0.0f, 0.0f); UIView.CommitAnimations(); } } public void EGORefreshScrollViewDidEndDraggingWithRefreshButton(UIScrollView scrollView) { bool _loading = false; if (_delegate != null) { _loading = _delegate.EGORefreshTableHeaderDataSourceIsLoading(this); _delegate.EGORefreshTableHeaderDidTriggerRefresh(this); } SetState(EGOPullRefreshState.EGOOPullRefreshLoading); UIView.BeginAnimations(null, IntPtr.Zero); UIView.SetAnimationDuration (0.2); scrollView.ContentInset = new UIEdgeInsets(60.0f, 0.0f, 0.0f, 0.0f); UIView.CommitAnimations(); } public void EGORefreshScrollViewDataSourceDidFinishedLoading(UIScrollView scrollView) { UIView.BeginAnimations(null, IntPtr.Zero); UIView.SetAnimationDuration (0.3); scrollView.ContentInset = new UIEdgeInsets(0.0f, 0.0f, 0.0f, 0.0f); UIView.CommitAnimations(); SetState(EGOPullRefreshState.EGOOPullRefreshNormal); } void SetState(EGOPullRefreshState state) { switch(state) { case EGOPullRefreshState.EGOOPullRefreshPulling: { _statusLabel.Text = "Release to refresh..."; CATransaction.Begin(); CATransaction.AnimationDuration = 0.18f; _arrowImage.Transform = CATransform3D.MakeRotation((nfloat)((System.Math.PI / 180.0) * 180.0f), 0.0f, 0.0f, 1.0f); CATransaction.Commit(); } break; case EGOPullRefreshState.EGOOPullRefreshNormal: { if(_state==EGOPullRefreshState.EGOOPullRefreshPulling) { CATransaction.Begin(); CATransaction.AnimationDuration = 0.18f; _arrowImage.Transform = CATransform3D.Identity; CATransaction.Commit(); } _statusLabel.Text = "Pull down to refresh..."; _activityView.StopAnimating(); CATransaction.Begin(); CATransaction.SetValueForKey(NSNumber.FromBoolean(true),new NSString("kCATransactionDisableActions")); _arrowImage.Hidden = false; _arrowImage.Transform = CATransform3D.Identity; CATransaction.Commit(); RefreshLastUpdatedDate(); } break; case EGOPullRefreshState.EGOOPullRefreshLoading: { _statusLabel.Text = "Loading..."; _activityView.StartAnimating(); CATransaction.Begin(); CATransaction.SetValueForKey(NSNumber.FromBoolean(true),new NSString("kCATransactionDisableActions")); _arrowImage.Hidden = false; CATransaction.Commit(); } break; default: break; } _state = state; } #endregion } } ViewController.cs using System; using UIKit; using Foundation; using CoreGraphics; namespace ScrollRefreshView { public partial class ViewController : UIViewController { #region Field WebViewDelegate _webdelegate; ScrollViewDelegate _scrolldelegate; EGORefreshTableHeaderDelegate _refreshtableheaderdelegate; EGORefreshTableHeaderView _refreshHeaderView; bool _reloading; #endregion #region Property public bool Reloading { get { return _reloading; } set { _reloading = value; } } public EGORefreshTableHeaderView RefreshHeaderView { get { return _refreshHeaderView; } } #endregion public ViewController(IntPtr handle) : base(handle) { } public override void ViewDidLoad() { base.ViewDidLoad(); WebView.Delegate = new WebViewDelegate(this); WebView.ScrollView.Delegate = new ScrollViewDelegate(this); LoadPage(); if (_refreshHeaderView == null) { _refreshHeaderView = new EGORefreshTableHeaderView(new CoreGraphics.CGRect(0, 0-WebView.ScrollView.Bounds.Size.Height, WebView.ScrollView.Bounds.Size.Width, WebView.ScrollView.Bounds.Height)); _refreshHeaderView.Delegate = new EGORefreshTableHeaderDelegate(this); WebView.ScrollView.AddSubview(_refreshHeaderView); } _refreshHeaderView.RefreshLastUpdatedDate(); } public void LoadPage() { WebView.LoadRequest(NSUrlRequest.FromUrl(NSUrl.FromString("http://www.baidu.com"))); } public override void DidReceiveMemoryWarning() { base.DidReceiveMemoryWarning(); // Release any cached data, images, etc that aren't in use. } } public class WebViewDelegate:UIWebViewDelegate { #region ViewController _webViewController; #endregion public override void LoadStarted(UIWebView webView) { _webViewController.Reloading=true; } public override void LoadingFinished(UIWebView webView) { _webViewController.Reloading=false; _webViewController.RefreshHeaderView.EGORefreshScrollViewDataSourceDidFinishedLoading(_webViewController.WebView.ScrollView); } public override void LoadFailed(UIWebView webView, NSError error) { _webViewController.Reloading=false; _webViewController.RefreshHeaderView.EGORefreshScrollViewDataSourceDidFinishedLoading(_webViewController.WebView.ScrollView); } public WebViewDelegate(ViewController webViewController) { _webViewController=webViewController; } } public class ScrollViewDelegate:UIScrollViewDelegate { #region ViewController _webViewController; #endregion public ScrollViewDelegate(ViewController webViewController) { _webViewController=webViewController; } public override void Scrolled(UIScrollView scrollView) { _webViewController.RefreshHeaderView.EGORefreshScrollViewDidScroll(scrollView); } public override void WillEndDragging(UIScrollView scrollView, CoreGraphics.CGPoint velocity, ref CGPoint targetContentOffset) { _webViewController.RefreshHeaderView.EGORefreshScrollViewDidEndDragging(scrollView); } public override void ScrollAnimationEnded(UIScrollView scrollView) { _webViewController.RefreshHeaderView.EGORefreshScrollViewDidEndDragging(scrollView); } } public class EGORefreshTableHeaderDelegate:IEGORefreshTableHeaderDelegate { #region ViewController _webViewController; #endregion public EGORefreshTableHeaderDelegate(ViewController webViewController) { _webViewController=webViewController; } #region IEGORefreshTableHeaderDelegate implementation public void EGORefreshTableHeaderDidTriggerRefresh(EGORefreshTableHeaderView view) { _webViewController.LoadPage(); } public bool EGORefreshTableHeaderDataSourceIsLoading(EGORefreshTableHeaderView view) { return _webViewController.Reloading; } public NSDate EGORefreshTableHeaderDataSourceLastUpdated(EGORefreshTableHeaderView view) { return NSDate.Now; } #endregion } } ViewController.designer.cs // WARNING // // This file has been generated automatically by Xamarin Studio to store outlets and // actions made in the UI designer. If it is removed, they will be lost. // Manual changes to this file may not be handled correctly. // using Foundation; using System.CodeDom.Compiler; namespace ScrollRefreshView { [Register ("ViewController")] partial class ViewController { [Outlet] public UIKit.UIWebView WebView { get; set; } void ReleaseDesignerOutlets () { if (WebView != null) { WebView.Dispose (); WebView = null; } } } }
试试其它关键字
下拉刷新
同语言下
.
C#实现的html内容截取
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
.
实现对图片上传的接收
.
去除字符串中的空格,回车,换行符转变成‘;’在按‘
.
按照回车换行符分割字符串
.
文件MD5码 比较,检测文件是否一样
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
DsonKing
贡献的其它代码
(
2
)
.
osx 下拉刷新
.
GIF抽帧
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3