Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set UiScrollView Frame on click of UIButton in Iphone?

I have UIScrollView on which I am using 2 UIButtons. UIScrollView initial frame is (0,0,768,1024). I want when I click on first button the UIScrollView y-cordinate position will be 500, means it will scrolldown 500 positions below to its actual position.

And when I click second Button which Will show on UIScrollView, Position Y-cordinate of UIScrollView y=535, then UIScrollView Move up to Position y= 0 again.

First button click UIScrollView y = 500 Second button click UIScrollView y = 0

Any hints from experts would be very welcome.

like image 849
Areeba Khan Avatar asked Nov 04 '22 06:11

Areeba Khan


1 Answers

Maybe you do not want to change the frame of the scroll view (this would just displace the whole view), but the contentOffset. This can be animated, too.

CGPoint offset = scrollView.contentOffset;
offset.y += 500;
[scrollView setContentOffset:offset animated:YES];
like image 200
Mundi Avatar answered Nov 14 '22 14:11

Mundi