3

これは私の UICollectionViewCell に書かれていますが、ピンチが呼び出されることはありません。

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self.contentView setBackgroundColor:[UIColor clearColor]];

        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0.0, 0.0, frame.size.width,frame.size.height)];
        UIPinchGestureRecognizer *pgr = [[UIPinchGestureRecognizer alloc]
                                         initWithTarget:self action:@selector(pinch:)];
        [self.imageView addGestureRecognizer:pgr];
        [self.contentView addSubview:imageView];
        imageView.contentMode=UIViewContentModeScaleAspectFill;
        [imageView setClipsToBounds:TRUE];

        _imageView = imageView;

        UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
        activityIndicator.center = _imageView.center;
        activityIndicator.hidesWhenStopped = YES;
        [_imageView addSubview:activityIndicator];
        _activityIndicator=activityIndicator;

        self.imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;


    }
    return self;
}
- (void)pinch:(UIPinchGestureRecognizer *)gesture {
    if (gesture.state == UIGestureRecognizerStateEnded
        || gesture.state == UIGestureRecognizerStateChanged) {
        NSLog(@"gesture.scale = %f", gesture.scale);

        CGFloat currentScale = self.frame.size.width / self.bounds.size.width;
        CGFloat newScale = currentScale * gesture.scale;

        if (newScale < 1.0) {
            newScale = 1.0;
        }
        if (newScale > 4.0) {
            newScale = 4.0;
        }

        CGAffineTransform transform = CGAffineTransformMakeScale(newScale, newScale);
        self.transform = transform;
        gesture.scale = 1;
    }
}
4

2 に答える 2

0

天気が正しいかどうかはわかりませんが、以下のコードから:

        [self.imageView addGestureRecognizer:pgr];
        [self.contentView addSubview:imageView];

iVar にジェスチャを追加しようとしていますが、ローカル変数を self.contentView に追加しています。

于 2014-03-06T12:01:12.180 に答える