0

スケール、回転、移動が同時に機能しない理由がわかりません..

多くの例を見てきましたが、問題が見つからないようです。最初はそれが問題だと思っていましたgestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizerが、そうではありませんでした:)

ここに私のコードがあります:

@implementation StoryEditorPageHolderView   
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
}
- (id)initWithProperty:(Property *)property scale:(CGFloat)scaleFactor pos:(CGPoint)point dustbin:(DustbinView *)dustBin{
    self = [super initWithFrame:CGRectZero];
    if(self){
        self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:property.imageName]];


        self.frame = CGRectMake(0, 0, self.imageView.frame.size.width, self.imageView.frame.size.height);
        [self addSubview:_imageView];

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

        UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
        [self addGestureRecognizer:rotationRecognizer];

        UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
        [panRecognizer setMinimumNumberOfTouches:1];
        [panRecognizer setMaximumNumberOfTouches:1];
        [self addGestureRecognizer:panRecognizer];

        UITapGestureRecognizer *tapProfileImageRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
        [tapProfileImageRecognizer setNumberOfTapsRequired:2];
        [self addGestureRecognizer:tapProfileImageRecognizer];



    }
    return self;
}

- (void)rotate:(UIRotationGestureRecognizer *)rotate {
    if (rotate.state == UIGestureRecognizerStateBegan) {
        prevRotation = 0.0;
    }

    float thisRotate = rotate.rotation - prevRotation;
    prevRotation = rotate.rotation;
    self.transform = CGAffineTransformRotate(self.transform, thisRotate);
}

- (void)scale:(UIPinchGestureRecognizer *)pinch {
    if (pinch.state == UIGestureRecognizerStateBegan)
        prevPinchScale = 1.0;

    float thisScale = 1 + (pinch.scale-prevPinchScale);
    prevPinchScale = pinch.scale;
    self.transform = CGAffineTransformScale(self.transform, thisScale, thisScale);
}

-(void)move:(UIPanGestureRecognizer *)pan {

    if (pan.state == UIGestureRecognizerStateBegan){
        prevPanPoint = [pan locationInView:self.superview];
    }

    CGPoint curr = [pan locationInView:self.superview];

    float diffx = curr.x - prevPanPoint.x;
    float diffy = curr.y - prevPanPoint.y;

    CGPoint centre = self.center;
    centre.x += diffx;
    centre.y += diffy;
    self.center = centre;

    prevPanPoint = curr;
}
@end

私はまた、.hファイルに次のUIGestureRecognizerDelegateように持っています:delegate

#import <Foundation/Foundation.h>


@class Property;
@class DustbinView;

@interface StoryEditorPropertyView : UIView <UIGestureRecognizerDelegate>

@property (strong, nonatomic) UIPanGestureRecognizer *panRecognizer;
@property (strong, nonatomic) UIPinchGestureRecognizer *pinchRecognizer;
@property (strong, nonatomic) UIRotationGestureRecognizer *rotationRecognizer;
@property (strong, nonatomic) UITapGestureRecognizer *tapProfileImageRecognizer;
@property (strong, nonatomic) UIImageView *imageView;
@property (strong, nonatomic) Property *property;
@property (nonatomic) CGPoint pointBegin;
@property (nonatomic) bool isRemoveable;
@property (nonatomic) CGFloat beginScale;
@property (strong, nonatomic) DustbinView *dustBin;

- (id)initWithProperty:(Property *)property scale:(CGFloat)scaleFactor pos:(CGPoint)point dustbin:(DustbinView *)dustBin;

@end
4

3 に答える 3

0

わかりました、あなたが間違っているのは、UIGestureRecognizer が適応するオブジェクトを追加していないことです。たとえば、

 UITapGestureRecognizer *tapProfileImageRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
    [tapProfileImageRecognizer setNumberOfTapsRequired:2];
    [self addGestureRecognizer:tapProfileImageRecognizer];

これはまさにこの行を除いて必要なものです

 [self addGestureRecognizer:tapProfileImageRecognizer];

これはクラスにジェスチャを追加しています。オブジェクトが必要です:)

だからこれをするだけ

 [self.view addGestureRecognizer:tapProfileImageRecognizer];

すべてのジェスチャで、うまくいくはずです:)クラスではなく、オブジェクトに追加していることを常に確認する必要があります

お役に立てれば!!

編集:

UIGestureRecognizers を UIView に置くことは、あなたがしていることをする方法です。あなたが今しなければならないことは、Xcodeの下に行くことです。

  • ファイル -> 新しいファイル
  • UIViewController サブクラスを作成する
  • その名前を確認してください...
  • .xib ファイルの下で、これを見つけます。

ここに画像の説明を入力

次に、UIView の場所を見たら、それをクリックします。これにより、UIView 属性パネルが表示されます。円の中に i がある小さなボタンに移動します。属性パネルの下にある青い部分です。それをクリックすると、次のように表示されます。

ここに画像の説明を入力

「UIView」と書かれたボックスがある場所

ここで、UIView のサブクラスを入力します。

それはあなたが抱えていた問題のいずれかを助けるはずです. それが役立つことを願っています! :)

于 2013-07-18T11:16:11.867 に答える
-1

viewDidLoadmethod ではなく、object( ) 自体ではなくinitview( ) にジェスチャを追加する必要があるジェスチャ コードを追加します。次のようにしてみてくださいいくつかの変更を加えましたself.viewself

-(void) viewDidLoad
{
        UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
        [self.view addGestureRecognizer:pinchRecognizer];

        UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
        [self.view addGestureRecognizer:rotationRecognizer];

        UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
        [panRecognizer setMinimumNumberOfTouches:1];
        [panRecognizer setMaximumNumberOfTouches:1];
        [self.view addGestureRecognizer:panRecognizer];

        UITapGestureRecognizer *tapProfileImageRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
        [tapProfileImageRecognizer setNumberOfTapsRequired:2];
        [self.view addGestureRecognizer:tapProfileImageRecognizer];
}
于 2013-07-18T11:20:12.723 に答える