所以,我有这个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];
}