tags:

views:

25

answers:

1

alt textI have a UIScrollView which has a UIView embedded in it. It have 2 buttons "scroll" and "unscroll".On clicking the "scroll" button, my scrollview scroll up from the bottom of the parent view. Everything works fine until here but when I click the "unscroll" button to push the scrollview back to where it came from, nothing happens. I have posted the entire code here. Please check where the fault lies !!. Already spent a sizeable amount of time on it.

-(IBAction)unscrollClicked:(id)sender
{
 //[viewController.view removeFromSuperview]; 
 [UIView beginAnimations:@"back to original size" context:nil];

 scrollView.contentSize=viewController.view.bounds.size;


 //scrollView.contentSize=viewController.view.bounds.size;
 [UIView commitAnimations];

}

-(IBAction)scrollClicked:(id)sender

{

 //viewController.view.backgroundColor=[UIColor orangeColor];
 viewController.view.frame=CGRectMake(0, 410, 320, 460);

 //[self.view addSubview:viewController.view];

 UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,40, 320, 400)];//(0,0,320,160)
 scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

 //[MyView setFrame:CGRectMake (0, 0, 320, 170)];
 viewController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
 scrollView.contentSize = viewController.view.bounds.size;


 scrollView.bounces = YES;
 scrollView.bouncesZoom = YES;
 scrollView.scrollEnabled = YES;
 scrollView.minimumZoomScale = 0.5;
 scrollView.maximumZoomScale = 5.0;
 scrollView.delegate = self;

 [scrollView addSubview: viewController.view];


 [self.view addSubview:scrollView];
 [self moveScrollView:scrollView];
}

-(void) moveScrollView:(UIScrollView *)scrollView

{

 CGFloat scrollamount=400;



 [scrollView setContentOffset:CGPointMake(0,scrollamount) animated:YES];
}
A: 

1st problem i see with this code is that you initialize scrollView in scrollClicked and never store pointer to it, so in unscrollClicked pointer should be nil. Another problem is that as far as i know, animation is conducted this way:

[UIView beginAnimations:@"Animate" context:nil];
[UIView setAnimationDuration:2];
[UIView setAnimationBeginsFromCurrentState:YES];

[somView setFrame:CGRectMake(100, 100, 100, 100)];

[UIView commitAnimations];
eviltrue
hey eviltrue I got it done now. I was a real fool to have been doing it the way I was. I finally did what you have recommended. Although the problem stands resolved, I am curious about the first part of what you have said:----- "initialize scrollView in scrollClicked and never store pointer to it, so in unscrollClicked pointer should be nil".
Bogus Boy
Well, I might miss something, but you define scrollView as local variable in scrollClicked, so it should be missed forever. In other words, I don't where from you get scrollView in unscrollClicked.=)
eviltrue