画像にタグを付けると表示されることはありませんか?どうして?なぜ私のビューはUIPanGestureRecognizerを認識できないのですか?
答えて
- (void)viewDidLoad {
[super viewDidLoad];
_view2 = [[V0 alloc ]initWithFrame:self.view.bounds];
CGRect a = self.view2.frame;
a.origin.x = 100;
a.origin.y = 150;
_view2.frame = a;
_view2.userInteractionEnabled = YES;
[self.view2 addGestureRecognizer:[[UIPanGestureRecognizer alloc]initWithTarget:self.view2 action:@selector(Up:)]];
私はinitWithFrameが、その後、私の見解は、私のジェスチャーを認識することができます追加
userInteractionEnabled
プロパティのデフォルト値はUIImageView
クラスにNO
に設定されています。たぶんそれはあなたの問題です。
は、このフラグメントのコードでチェック:このプロパティは、UIViewの親クラスから継承されます。このクラスは、このプロパティのデフォルト値をNOに変更します。
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:imageView];
imageView.userInteractionEnabled = YES;
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognized:)];
[imageView addGestureRecognizer:panGesture];
}
- (void)panGestureRecognized:(UIGestureRecognizer *)gestureRecognizer {
NSLog(@"It Works!");
}
私はimage.Viewをmain.storybordで作成し、userInteractionEnabledをyesにして、このようにしてみます。有効ではありません。 –
このコードを適用してうまく働い:
-(void)initialization
UIPanGestureRecognizer *panRecognizer = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)] autorelease];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[imageview addGestureRecognizer:panRecognizer];
imageview.userInteractionEnabled = YES;
}
- (void)move:(UIPanGestureRecognizer *)gestureRecognizer
{
UIView *piece = imageview;
[self adjustAnchorPointForGestureRecognizer:gestureRecognizer];
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
CGPoint translation = [gestureRecognizer translationInView:[piece superview]];
CGPoint translatedCenter = CGPointMake([piece center].x + translation.x, [piece center].y + translation.y);
CGPoint center = [self centerWithBounds:translatedCenter andViewFrame:[piece frame] andBoundingFrame:[[piece superview] frame]];
[piece setCenter:center];
[gestureRecognizer setTranslation:CGPointZero inView:[piece superview]];
}
}
初期化をどこに追加すればよいですか?私はviewDidLoadでコードを削除する必要がありますか? –
あなたはviewdidload [self initialization]でこの初期化メソッドを呼び出す必要があります。 –
- 1. セレクタを認識できないのはなぜですか?
- 2. 私のルートが私のプロトコルを認識しないのはなぜですか?
- 3. メインファイルからヘッダーファイルの@propertiesを認識できないのはなぜですか?
- 4. Windowsでgitがリモートブランチを認識できないのはなぜですか?
- 5. Backbone.jsアプリで "this。$ el"を認識できないのはなぜですか?
- 6. クロムがこのマニフェストファイルを認識できないのはなぜですか?
- 7. 私の意図が私の活動を認識できないのはなぜですか
- 8. smtp.gmail.comが認識できないコマンドを返すのはなぜですか?
- 9. コンパイラが私のコントロールを認識しないのはなぜですか?
- 10. qUnitが私のテストを認識しないのはなぜですか?
- 11. スロンは私のスタブをなぜ認識しないのですか?
- 12. Thorが私のコマンドラインオプションを認識しないのはなぜですか?
- 13. Resharperが私のWeb参照を認識しないのはなぜですか?
- 14. なぜ私のプログラムは.txtファイルを認識しないのですか
- 15. keras.applicationsが私の象を認識しないのはなぜですか?
- 16. IntelliJ Ideaが私のSpekテストを認識しないのはなぜですか?
- 17. laravelが私のモデルを認識しないのはなぜですか?
- 18. XcodeがCosineを認識しないのはなぜですか?
- 19. コンパイラがMath.PI()を認識しないのはなぜですか?
- 20. getconfがBUFSIZを認識しないのはなぜですか?
- 21. datetimeが文字列を認識できないのはなぜですか?
- 22. なぜOracle LinuxはPHPパッケージを認識できないのですか?
- 23. なぜadbが私のネクサス4をマックで認識しないのですか
- 24. Swift 3が私にボタンタップを認識させないのはなぜですか?
- 25. CythonのC++の例でC++を認識できない、なぜですか?
- 26. Qtが私のヘッダファイルもライブラリファイルも認識しないのはなぜですか?
- 27. 私のomp.hパスが認識されないのはなぜですか?
- 28. 私の「pg」宝石はなぜ認識されないのですか?
- 29. フレックスコードに認識できないルールがあるのはなぜですか?
- 30. セレクタが認識されないのはなぜですか?
UIPanGestureRecognizerに代理人を追加し、ターゲットはself not.videoでなければなりません.vi ew1 – vaibby
イメージの代わりにポストコードを入力してください。 –
あなたはより良い答えのために書かれたものを投稿してください。初心者では普通です:) –