Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

How to get the Xamarin.Forms ScrollView control's OnScroll event and get the ContentOffset.Y?

$
0
0

Hello, Every one,

It's my first time to ask question here.

Xamarin.Forms says it abstracted native UI controls from platforms to it's shared controls, but I found lots of properties were not implemented. For example ScrollView control, it has only few properties, I want use the OnScoll event to get the ContentOffset. I think it's a MUST-HAVE property. I can't found what I need in ScrollView control, and how about other controls?

I must ask Xamarin Inc. why. And where's the Xamarin.Forms roadmap?

I just want to build a page looks like the home page of the famous App Tictail. On the home page and some else, when we pull down/up the page, the top image can be zoom in/out, it's very good effect.

With Xcode and Objective-C, it just took me 1 hours to finished the effect.

But using Xamarin.Forms now, I was wondered.

Who can give me an answer?

Sorry for my poor english.

Following is OC code: (Every one here can ask me to get the full project by email: xuebo@live.com)

  • (void)addview {
    _W = 1024;
    _H = 1024;

    _w = [[UIScreen mainScreen] bounds].size.width;
    _myimageview.frame = CGRectMake(0, 0, _w, _w * _H / _W);
    _h = _myimageview.frame.size.height;

    UIView *headview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _w, _h)];
    headview.backgroundColor = [UIColor clearColor];

    UILabel *lab = [[UILabel alloc]initWithFrame:_myimageview.frame];
    lab.text = @不要摸我!;
    lab.font = [UIFont systemFontOfSize:25];
    lab.textColor =[UIColor whiteColor];
    lab.textAlignment = NSTextAlignmentCenter;
    [headview addSubview:lab];
    _mytableview.tableHeaderView = headview;

    _SearchTextField = [[UITextField alloc]initWithFrame:CGRectMake(_w / 7, 50, _w * 5 / 7, 30)];
    _SearchTextField.layer.cornerRadius = 4;
    _SearchTextField.backgroundColor = [UIColor whiteColor];
    _SearchTextField.placeholder = @Search;
    [self.view addSubview:_SearchTextField];
    [self.view bringSubviewToFront:_SearchTextField];

    _field_y = _SearchTextField.center.y;
    }

  • (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat y = scrollView.contentOffset.y;
    NSLog(@== %f, y);

    if( y<= 0)
    {
    _myimageview.frame=CGRectMake(y * _W / _H / 2, 0, _w - y * _W / _H, _h - y);
    _SearchTextField.alpha = 1;
    }
    else
    {
    _myimageview.frame = CGRectMake(0, -y / 2, _w, _h);
    _SearchTextField.center = CGPointMake(_SearchTextField.center.x, _field_y - y / 4 );
    if (_SearchTextField.center.y >= 20 && _SearchTextField.center.y <= 50)
    {
    _SearchTextField.alpha = (_SearchTextField.center.y - 20) / 30;
    }
    }
    }


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>