Xamarin.forms 如何使滚动条在ios设备中始终以xamarin形式显示,并将滚动条移到屏幕左侧?

Xamarin.forms 如何使滚动条在ios设备中始终以xamarin形式显示,并将滚动条移到屏幕左侧?,xamarin.forms,Xamarin.forms,如何使滚动条在IOS设备中以Xamarin格式始终可见,并将滚动条移到屏幕左侧? 我尝试了以下链接: 但得到的例外是 事件注册正在覆盖现有委托。要么就用 事件或您自己的委托:hupp.iOS.Models.CustomScrollDelegate UIKit.UIScrollView+\u UIScrollViewDelegate 公共类CustomScrollViewRenderer:ScrollViewRenderer { 公众观景台; 受保护的重写异步void OnElementChan

如何使滚动条在IOS设备中以Xamarin格式始终可见,并将滚动条移到屏幕左侧?
我尝试了以下链接:

但得到的例外是

事件注册正在覆盖现有委托。要么就用 事件或您自己的委托:hupp.iOS.Models.CustomScrollDelegate UIKit.UIScrollView+\u UIScrollViewDelegate

公共类CustomScrollViewRenderer:ScrollViewRenderer { 公众观景台; 受保护的重写异步void OnElementChanged(VisualElementChangedEventArgs e) { 基础。一个要素发生变化(e); //UIScrollView IOScrollView=(UIScrollView)NativeView; this.ShowsVerticalScrollIndicator=((CustomScrollViewLesson)e.NewElement).IsVerticalScrollbarEnabled; this.showrizontalscrollingindicator=((CustomScrollViewLesson)e.NewElement).IsHorizontalScrollbarEnabled; this.IndicatorStyle=UIScrollViewIndicatorStyle.White; this.scrollIndicationSets=新的UIEdgeInsets(0,30,0,30); this.FlashScrollIndicators(); //隐藏默认的滚动指示器。 this.ShowsVerticalScrollIndicator=false; //集合委托 CustomScrollDelegate CustomScrollDelegate=新的CustomScrollDelegate(); this.Delegate=customScrollDelegate; //创建自定义指示器的背景视图。 双帧高度=this.Frame.Size.Height; double frameWidth=this.Frame.Size.Width; 双Barbackgroundth=6; double statusBarHeight=20;//this.ScrollIndicationSets=新的UIEdgeInsets(0,0,0,this.Bounds.Size.Width-10); UIView barBackgroundView=新UIView(); CGRect barBVRect=新的CGRect(帧宽度-barBackgroundWidth,statusBarHeight,barBackgroundWidth,frameHeight); barBackgroundView.Frame=barBVRect; barBackgroundView.BackgroundColor=UIColor.Gray; barBackgroundView.Layer.CornerRadius=2; barBackgroundView.Layer.MasksToBounds=true; //创建自定义指示器的条形图。 bar=新的UIScrollView(); CGRect-barRect=新的CGRect(1,0,4,0); 杆。框架=杆; bar.BackgroundColor=UIColor.White; bar.Layer.CornerRadius=2; bar.Layer.MasksToBounds=true; //将视图添加到tableview的superview中。 barBackgroundView.AddSubview(条形图); this.Superview.AddSubview(barBackgroundView);//这里还获取Superview中的异常null值。因此,我在调试时进行了注释 customScrollDelegate.bar=bar; //将条形图转换为委托。 } 公共覆盖无效布局子视图() { base.LayoutSubviews(); Console.WriteLine(“加载结束!!!”; double contentHeight=this.ContentSize.Height; 双帧高度=this.Frame.Size.Height; 双条高=帧高*帧高/内容高; //在表格视图完成加载时重置条形图高度。 CGRect barRect=新的CGRect(bar.Frame.X、bar.Frame.Y、bar.Frame.Width、bar高度); 杆。框架=杆; } } 公共类CustomScrollDelegate:UIKit.UIScrollViewDelegate { 公众观景台; 双巴里; 公共覆盖无效滚动(UIScrollView滚动视图) { 双y=scrollView.ContentOffset.y; double contentHeight=scrollView.ContentSize.Height; 双帧高度=scrollView.Frame.Size.Height; 双条高=帧高*帧高/内容高; barY=y/(内容高度-帧高度)*(帧高度-栏高度); //当杆超过顶部时,切断杆的高度。 if(barY<0) { 栏杆高度=栏杆高度+栏杆高度; barY=0; } //当杆超过底部时,切断杆的高度。 如果(条形图>(框架高度-条形图高度)) { barHeight=barHeight-(barY-(frameHeight-barHeight)); } //重置barView矩形。让我们移动!!! CGRect barRect=新的CGRect(bar.Frame.X,barY,bar.Frame.Width,barHeight); 杆。框架=杆; } }
请给出解决方案并提前感谢

您好,您能否分享项目中使用的xaml代码,这样我们就可以知道设计的布局(ScrollView或ListView uesd)。只有ScrollView使用,ListView未使用,所以我改为CustomScrollDelegate:UIKit.UIScrollViewDelegate而不是CustomScrollDelegate:UIKit.UITableViewDelegateOK,谢谢回复,我会在ScrollView中查看。如果与CustomScrollDelegate的代码共享,那会更好。非常感谢,我更新了上面的代码。谢谢分享,我会检查它。如果解决方案将在此处更新。
    public class CustomScrollViewRenderer : ScrollViewRenderer
{

    public UIView bar;

    protected override async void OnElementChanged(VisualElementChangedEventArgs e)
    {
        base.OnElementChanged(e);
       // UIScrollView iosScrollView = (UIScrollView)NativeView;

        this.ShowsVerticalScrollIndicator = ((CustomScrollViewLesson)e.NewElement).IsVerticalScrollbarEnabled;
        this.ShowsHorizontalScrollIndicator = ((CustomScrollViewLesson)e.NewElement).IsHorizontalScrollbarEnabled;

        this.IndicatorStyle = UIScrollViewIndicatorStyle.White;
        this.ScrollIndicatorInsets = new UIEdgeInsets(0, 30, 0, 30);
        this.FlashScrollIndicators();
        //Hide the default Scroll Indicator.
         this.ShowsVerticalScrollIndicator = false;
        //Set Delegate
        CustomScrollDelegate customScrollDelegate = new CustomScrollDelegate();
        this.Delegate = customScrollDelegate;


        //Create the background view of custom indicator.
        double frameHeight = this.Frame.Size.Height;
        double frameWidth = this.Frame.Size.Width;

        double barBackgroundWidth = 6;
        double statusBarHeight = 20; //this.ScrollIndicatorInsets = new UIEdgeInsets(0, 0, 0, this.Bounds.Size.Width - 10);
        UIView barBackgroundView = new UIView();
        CGRect barBVRect = new CGRect(frameWidth - barBackgroundWidth, statusBarHeight, barBackgroundWidth, frameHeight);
        barBackgroundView.Frame = barBVRect;
        barBackgroundView.BackgroundColor = UIColor.Gray;
        barBackgroundView.Layer.CornerRadius = 2;
        barBackgroundView.Layer.MasksToBounds = true;

        //Create the bar of the custom indicator.
        bar = new UIScrollView();
        CGRect barRect = new CGRect(1, 0, 4, 0);
        bar.Frame = barRect;
        bar.BackgroundColor = UIColor.White;
        bar.Layer.CornerRadius = 2;
        bar.Layer.MasksToBounds = true;

        //Add the views to the superview of the tableview.
        barBackgroundView.AddSubview(bar);
        this.Superview.AddSubview(barBackgroundView);//here also getting exception null value in superview.so i commented while debug
        customScrollDelegate.bar = bar;

        //Transfer the bar view to delegate.

    }

    public override void LayoutSubviews()
    {
        base.LayoutSubviews();
        Console.WriteLine("End of loading!!!");
        double contentHeight = this.ContentSize.Height;
        double frameHeight = this.Frame.Size.Height;
        double barHeight = frameHeight * frameHeight / contentHeight;


        //Reset the bar height when the table view finishes loading.
        CGRect barRect = new CGRect(bar.Frame.X, bar.Frame.Y, bar.Frame.Width, barHeight);
        bar.Frame = barRect;
    }
}
    public class CustomScrollDelegate : UIKit.UIScrollViewDelegate
{
    public UIView bar;
    double barY;

    public override void Scrolled(UIScrollView scrollView)
    {
        double y = scrollView.ContentOffset.Y;
        double contentHeight = scrollView.ContentSize.Height;
        double frameHeight = scrollView.Frame.Size.Height;

        double barHeight = frameHeight * frameHeight / contentHeight;
        barY = y / (contentHeight - frameHeight) * (frameHeight - barHeight);

        //Cut the bar Height when it over the top.
        if (barY < 0)
        {
            barHeight = barHeight + barY;
            barY = 0;
        }

        //Cut the bar height when it over the bottom.
        if (barY > (frameHeight - barHeight))
        {
            barHeight = barHeight - (barY - (frameHeight - barHeight));
        }

        //Reset the barView rect. Let's move!!!
        CGRect barRect = new CGRect(bar.Frame.X, barY, bar.Frame.Width, barHeight);
        bar.Frame = barRect;

    }

}