I have a UIScrollView which has a UIView embedded in it. It scrolls up from bottom on a buttonClick, the button is located in another view. When it scrolls up it partly covers the calling view i.e view on which the button is 开发者_如何学编程located. Now, I have another button that is supposed to push this scroll view down. This button doesn't seem to be working. I have posted the entire code. Please Help!!
-(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];
}
Try using the zoomToRect method.
I think you should modify your move method. As it is, it shows content at a fixed origin ( height 400), but after one invokation it should not do anything, since contentOffset is already at 400. Try this:
-(void) moveScrollView:(UIScrollView *)scrollView upwards:(BOOL)up {
CGFloat scrollamount=400;
if ( up)
[scrollView setContentOffset:CGPointMake(0,scrollamount) animated:YES];
else
[scrollView setContentOffset:CGPointMake(0,0) animated:YES];
}
And invoke like this:
[self moveScrollView:scrollView upwards:YES]; // or NO for moving down
精彩评论