自定义 UIRefreshControl 动画
Custom UIRefreshControl animation
我正在尝试创建显示我公司徽标的自定义 UIRefreshControl 动画。到目前为止,我可以在刷新时启动动画,不刷新时停止。
我想要的是控制 UIRefreshControl 的 draginEvent 并使徽标在 UIRefreshControl 被向下拖动时做一些事情(增加图像 alpha 或类似的东西)。
我知道拖动距离必须有句柄,但我找不到任何可以用来获取此值的东西。有人可以帮我吗
到目前为止,这是我的代码。
public sealed class FormsUIRefreshControl : UIRefreshControl
{
UIImageView animatedCircleImage;
nfloat visibility = 0.0f;
public FormsUIRefreshControl()
{
this.ValueChanged += (object sender, EventArgs e) =>
{
var command = RefreshCommand;
if(command == null)
return;
command.Execute(null);
};
BackgroundColor = UIColor.Clear;
//Alpha = (nfloat)0.30;
animatedCircleImage = new UIImageView(new UIImage("loadingLogo.png"));
animatedCircleImage.Frame = new RectangleF(110, 10, 100, 50);
animatedCircleImage.BackgroundColor = UIColor.Blue;
animatedCircleImage.AnimationImages = new UIImage[] {
UIImage.FromBundle ("loadingLogo.png")
, UIImage.FromBundle ("loadingLogo1.png")
, UIImage.FromBundle ("loadingLogo2.png")
, UIImage.FromBundle ("loadingLogo3.png")
, UIImage.FromBundle ("loadingLogo4.png")
, UIImage.FromBundle ("loadingLogo5.png")
, UIImage.FromBundle ("loadingLogo6.png")
, UIImage.FromBundle ("loadingLogo7.png")
};
animatedCircleImage.AnimationRepeatCount = 0;
animatedCircleImage.AnimationDuration = .5;
//animatedCircleImage.StartAnimating();
AddSubview (animatedCircleImage);
//ClipsToBounds = true;
TintColor = UIColor.Clear;
}
public override void BeginRefreshing ()
{
base.BeginRefreshing ();
animatedCircleImage.StartAnimating ();
}
public override void EndRefreshing ()
{
base.EndRefreshing ();
animatedCircleImage.StopAnimating ();
}
您需要 scrollViewDidScroll。但这适用于使用 TableView/TableViewController 的 class。也许您可以从此处使用 contentOffset 为您的 FormsUIRefreshControl 调用 public 动画方法。在 Objective C:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"Y Offset: %f", scrollView.contentOffset.y);
}
我的 0.02 美分 (Swift):
// MARK: - Scroll View Delegate
override func scrollViewDidScroll(scrollView: UIScrollView) {
// Distance the table has been pulled >= 0.
let pullDistance: CGFloat = max(0.0, -refreshControl.frame.origin.y)
// Calculate the pull ratio, between 0.0-1.0.
let pullRatio: CGFloat = min(max(pullDistance, 0.0), 100.0) / 100.0
// Update the cloud icon alpha for a nice effect.
yourCustomLogoImageEtc.alpha = pullRatio
}
我正在尝试创建显示我公司徽标的自定义 UIRefreshControl 动画。到目前为止,我可以在刷新时启动动画,不刷新时停止。
我想要的是控制 UIRefreshControl 的 draginEvent 并使徽标在 UIRefreshControl 被向下拖动时做一些事情(增加图像 alpha 或类似的东西)。
我知道拖动距离必须有句柄,但我找不到任何可以用来获取此值的东西。有人可以帮我吗
到目前为止,这是我的代码。
public sealed class FormsUIRefreshControl : UIRefreshControl
{
UIImageView animatedCircleImage;
nfloat visibility = 0.0f;
public FormsUIRefreshControl()
{
this.ValueChanged += (object sender, EventArgs e) =>
{
var command = RefreshCommand;
if(command == null)
return;
command.Execute(null);
};
BackgroundColor = UIColor.Clear;
//Alpha = (nfloat)0.30;
animatedCircleImage = new UIImageView(new UIImage("loadingLogo.png"));
animatedCircleImage.Frame = new RectangleF(110, 10, 100, 50);
animatedCircleImage.BackgroundColor = UIColor.Blue;
animatedCircleImage.AnimationImages = new UIImage[] {
UIImage.FromBundle ("loadingLogo.png")
, UIImage.FromBundle ("loadingLogo1.png")
, UIImage.FromBundle ("loadingLogo2.png")
, UIImage.FromBundle ("loadingLogo3.png")
, UIImage.FromBundle ("loadingLogo4.png")
, UIImage.FromBundle ("loadingLogo5.png")
, UIImage.FromBundle ("loadingLogo6.png")
, UIImage.FromBundle ("loadingLogo7.png")
};
animatedCircleImage.AnimationRepeatCount = 0;
animatedCircleImage.AnimationDuration = .5;
//animatedCircleImage.StartAnimating();
AddSubview (animatedCircleImage);
//ClipsToBounds = true;
TintColor = UIColor.Clear;
}
public override void BeginRefreshing ()
{
base.BeginRefreshing ();
animatedCircleImage.StartAnimating ();
}
public override void EndRefreshing ()
{
base.EndRefreshing ();
animatedCircleImage.StopAnimating ();
}
您需要 scrollViewDidScroll。但这适用于使用 TableView/TableViewController 的 class。也许您可以从此处使用 contentOffset 为您的 FormsUIRefreshControl 调用 public 动画方法。在 Objective C:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"Y Offset: %f", scrollView.contentOffset.y);
}
我的 0.02 美分 (Swift):
// MARK: - Scroll View Delegate
override func scrollViewDidScroll(scrollView: UIScrollView) {
// Distance the table has been pulled >= 0.
let pullDistance: CGFloat = max(0.0, -refreshControl.frame.origin.y)
// Calculate the pull ratio, between 0.0-1.0.
let pullRatio: CGFloat = min(max(pullDistance, 0.0), 100.0) / 100.0
// Update the cloud icon alpha for a nice effect.
yourCustomLogoImageEtc.alpha = pullRatio
}