3

Possible Duplicate:
Programmatically scroll a UIScrollView

Currently, I am developing an App in which I have UIScrollView and some buttons are programatically inserted in scroll view.Scrolling of these added buttons work fine for me. but I want to add two more button & on one button click scroll view scrolling to bottom side and display bottom last

buttons and when I click on second button it scroll to top side and it show top most button. I have tried so much but can't succeeded. How can I solve this? Thanks in advance.

Community
  • 1
  • 1
Vishal
  • 8,246
  • 6
  • 37
  • 52

3 Answers3

7
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 20, 320, 400)];
scrollView.backgroundColor=[UIColor lightGrayColor];
scrollView.contentSize=CGSizeMake(320, 500);
scrollView.showsVerticalScrollIndicator=YES;
[self.view addSubview:scrollView];

If Scroll Size is known then we can set the button click event

-(void)buttonCkicked:(UIButton*)sender
{
    if (sender.tag==1001) {
        [scrollView setContentOffset:CGPointMake(0, 100) animated:YES];
    }
    if (sender.tag==1002) {
        [scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
    }
}
3

This may solve ur pbm

-(IBAction) clickfirstbutton 
{
   [scrollview setContentOffset:CGPointMake(0, (intvalue to the positon of two buttons)) animated:TRUE];
}

-(IBAction) clicksecondbutton
{
   [scrollview setContentOffset:CGPointMake(0, 0) animated:TRUE];
}
Nazik
  • 8,696
  • 27
  • 77
  • 123
2
-(IBAction)btn1_Clicked:(id)sender{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    yourScrollView.frame=CGRectMake(0, -scrollView.contentSize.height + 360, 320, scrollView.contentSize.height);/// set y (starting point) with your scrollview height
    [UIView commitAnimations];
}

-(IBAction)btn2_Clicked:(id)sender{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    yourScrollView.frame=CGRectMake(0,0 , 320, scrollView.contentSize.height);
    [UIView commitAnimations];
}
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70