我有一个UIScrollView,其中嵌入了UIView。它从按钮单击底部向上滚动,按钮位于另一个视图中。当它向上滚动时,它部分覆盖了调用视图,即按钮所在的视图。现在,我有另一个按钮,可以推动这个滚动视图。此按钮似乎不起作用。我已经发布了整个代码。请帮助!!
-(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];
}
答案 0 :(得分:0)
尝试使用zoomToRect方法。
答案 1 :(得分:0)
我认为你应该修改你的移动方法。实际上,它显示的内容为 固定原点(高度400),但在一次调用之后它不应该做任何事情,因为contentOffset已经是400.试试这个:
-(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];
}
并像这样调用:
[self moveScrollView:scrollView upwards:YES]; // or NO for moving down