c# - 自定义 UIRefreshControl 动画

标签 c# xamarin.ios uirefreshcontrol

我正在尝试创建显示我公司 Logo 的自定义 UIRefreshControl 动画。到目前为止,我能够在刷新时启动动画,在不刷新时停止。

我想要的是控制 UIRefreshControl 的 draginEvent 并使 Logo 在 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 的类。也许您可以从此处使用 contentOffset 为您的 FormsUIRefreshControl 调用公共(public)动画方法。在 objective-c 中:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSLog(@"Y Offset: %f", scrollView.contentOffset.y);
}

关于c# - 自定义 UIRefreshControl 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30737580/

相关文章:

xamarin.ios - MonoTouch Dialog 在对话框底部添加工具栏

ios - UIRefreshControl 无法正常工作

c# - 按位运算符让我见鬼去吧

c# - 用户控件中的依赖属性仅适用于第一个实例

ios - 即使设备锁定,如何循环播放 AVQueuePlayer 中的歌曲队列?

iOS VideoPreview 横向颠倒

ios - 在显示之前更改 UIRefreshControl 标题 - Objective-c iOS

iOS 10.0 UIRefreshControl 不显示指示器

c# - 将带有参数的 c# 回调方法传递给 c++ dll 会导致 System.ExecutionEngineException

c# - Fluent NHibernate 组件映射问题