所以,我有这个UIScrollView
在开始缩放时效果很好。我设置了最小和最大缩放比例,并设置了必要的委托方法-(UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView;
。最初我在它上面设置了两个子视图(一个是小球的一个),显然,一个会缩小,而另一个则没有(球视图)。我想改变它,以便它们都正确缩放,所以我将较小的视图(球)添加到另一个子视图列表中。但是,现在没有缩放。如果有必要,我可以发布代码,但我想知道这个问题听起来是否为任何人所熟悉,以及他们是否有答案。
编辑:这是代码
头文件
@interface NumberLineScroll : UIScrollView {
NumberLine* nline;
id <UIScrollViewDelegate> delegate;
}
@property(nonatomic, retain)id <UIScrollViewDelegate> delegate;
- (NumberLine*)getLine;
@end
主档
#import "NumberLineScroll.h"
@implementation NumberLineScroll
@synthesize delegate;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setUserInteractionEnabled:YES];
nline = [[NumberLine alloc] initWithFrame:CGRectMake(0, 0, 2100, 400)];
[self addSubview:nline];
self.minimumZoomScale = 0.5;
self.maximumZoomScale = 3.0;
}
return self;
}
- (NumberLine*)getLine {return nline;}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {}
- (void)dealloc {
[nline release];
[super dealloc];
}
@end
这是滚动视图。 nline只是一个带有球视图的视图,在drawRect
期间绘制了一条线。这是委托类中的方法实现:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {}
- (void)doTest {NSLog(@"test");}
-(UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView {return [nline getLine];}
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
NSLog(@"Zoom ended");
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
Ball* ball = [[nline getLine] getBall];
CGPoint newCenter = ball.center;
newCenter.y = ball.center.y * scrollView.zoomScale;
newCenter.x = ball.center.x * scrollView.zoomScale;
[[nline getLine] changeBalLoc:newCenter];
}
答案 0 :(得分:1)
我认为你想要在放置在UIScrollView上的zoomIn / Out时管理子视图
注意两件事情首先从下面的委托方法返回那个largeSubview(包含球视图作为子视图)缩放时间。
-(UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView
{
return largeSubvew
//here that view contains smallView(ball) too as mentioned you changed
}
在ZoomIn / Out scrollView中管理小视图的位置。
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
CGPoint newCenter = smallerViewCenter;
//smallerViewCenter contains the center point of smallerView(say ball),has set at load time, and only once
newCenter.y = smallerView.y * scrollView.zoomScale;
//new center is calculated on original position
newCenter.x = smallerView.x * scrollView.zoomScale;
smallerView.center = newCenter;
}