それで、UIScrollView
最初はズームでうまくいっていたこれがあります。最小ズーム スケールと最大ズーム スケールを設定し、必要なデリゲート メソッドをセットアップしました-(UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView;
。もともと私はそれに2つのサブビューを設定していました(1つはボールの小さなものです)、明らかに、1つはズームアウトし、もう1つはそうではありませんでした(ボールビュー)。両方が正しくスケーリングされるようにこれを変更したかったので、小さい方のビュー (ボール) をもう一方のサブビューのリストに追加しました。ただし、現在、ズームはありません。必要に応じてコードを投稿することもできますが、この問題が誰にでも知られているように聞こえるかどうか、また提供できる回答があるかどうか疑問に思っていました.
編集:ここにコードがあります
ヘッダファイル
@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];
}