1

それで、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];
}
4

1 に答える 1

1

UIScrollViewの上にズームイン/アウトが配置されているときにサブビューを管理する方法が必要だと思います

デリゲート メソッドの下からのズーム時に、最初にその largeSubview (サブビューとしてボール ビューを含む) を返す 2 つのことに注意してください。

-(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;

 }
于 2013-05-22T04:00:33.867 に答える