0

だから、私はプログラムでズーム方法を使ってUIScrollViewを作成することができましたが、ズームで発生している問題を解決する方法が行き詰まっています。

  1. ピンチジェスチャを行った場所で拡大/縮小するポイントがズームインまたはズームアウトすると、コーナーで発生します。

  2. ズームインまたはズームアウトすると、境界の外側に余分なスペースが残り、画像の幅と高さの半分を超えて画像をスクロールできなくなります。

これを除けば、私はそれを100%動作させることに非常に近いです。achorpointsを試してみましたが、スクロールビューとイメージビューがこれに反応しないようです。

コードリストの重要なものは次のとおりです。

UIScrollView *mapScrollView;

UIImageView *mapImageView;

CGFloat lastScale = 0;

NSMutableArray *map_List;


- (id)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    if (self) {

  mainMenuAppDelegate *del = (mainMenuAppDelegate *)[[UIApplication sharedApplication] delegate];

  map_List = [[NSMutableArray alloc] init];
  [map_List addObject:@"Pacific_Map_8bit.png"];
  [map_List addObject:@"Atlantic_Map_8bit.png"];


  CGRect mapScrollViewFrame = CGRectMake(0, 0, 1024, 768);

  mapScrollView = [[UIScrollView alloc]   initWithFrame:mapScrollViewFrame];

  mapScrollView.contentSize = CGSizeMake(2437, 1536);


  UIImage *mapImage = [UIImage imageNamed:[map_List objectAtIndex:mapNum]];

  mapImageView = [[UIImageView alloc] initWithImage: mapImage];

  mapScrollView.bounces = NO;

  [mapImage release];

  [mapScrollView addSubview:mapImageView];
  [self addSubview:mapScrollView];

  mapImageView.userInteractionEnabled = YES;


  UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
  [mapImageView addGestureRecognizer:pinchRecognizer];

  [pinchRecognizer release];
    }
    return self;

} 
// the scale method thats triggered to zoom when pinching
-(void)scale:(id)sender {

 if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {

  lastScale = 1.0;
  return;
 }

 CGFloat scale = 1.0 - (lastScale - [(UIPinchGestureRecognizer*)sender scale]);

 NSLog(@"map scale %f", scale);

 CGFloat mapWidth = mapImageView.frame.size.width;
 CGFloat mapHeight = mapImageView.frame.size.height;
 NSLog(@"map width %f", mapWidth);

 if(scale>=1 & mapWidth<=4000 || scale<1 & mapWidth>=1234){

  CGAffineTransform currentTransform = [(UIPinchGestureRecognizer*)sender view].transform;
  CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale);
  [[(UIPinchGestureRecognizer*)sender view] setTransform:newTransform];

  lastScale = [(UIPinchGestureRecognizer*)sender scale];

 }

 mapScrollView.contentSize = CGSizeMake(mapWidth, mapHeight);

}

ありがとう!

4

1 に答える 1

2

UIScrollView組み込みのズームサポートがあります。minimumZoomScaleとプロパティを設定し、maximumZoomScaleを使用してズームに使用するビューを返すだけviewForZoomingInScrollViewです。

于 2011-01-28T23:18:49.857 に答える