2016-04-12 17 views
0

iOSでタッチ/クリック/プレッシャー(必要に応じて呼び出す)をシミュレートできる方法がないかどうかを知りたいと思います。 これについて追加することがあるかどうかわかりません... Objective-cでコーディングしていることを除いては。iOSのタッチをシミュレートする方法

事前に感謝します。 EDIT

:ここ

- (void)collectionViewTableLayoutManager:(DRCollectionViewTableLayoutManager *)manager collectionView:(UICollectionView *)collectionView didSelectCellAtRow:(NSUInteger)row column:(NSUInteger)column indexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"SELECTED: %ld.%ld/%ld.%ld", (long)indexPath.section, (long)indexPath.row, (long)row, (long)column); 
} 

はdragNdropを扱う私の方法であって、ここで は私が(それがログに私を見る)私が選択した例座標を有することを可能にする方法であり、私のPostItの(詳細についてはコメントを参照してください):

-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer{ 
CGPoint translation = [recognizer translationInView:self]; 
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y); 

//Here to know the coordinates of the drop 
if(recognizer.state == UIGestureRecognizerStateEnded){   
    CGPoint centerPointOfView = [recognizer locationInView:self.superview]; 
    NSLog(@"X - %f, Y - %f",centerPointOfView.x,centerPointOfView.y); 
} 

[recognizer setTranslation:CGPointMake(0, 0) inView:self]; 
} 
+0

:ここ

は私の新しい方法がどのように見えるかですか? –

+1

だから、私はオブジェクト(正確には、私のペン先のSelectPostIt.xibから来たPostIt)を持っている。これはドラッグ可能です。それから私は、複数のケースでコレクションビューを持っています。私がこれらのケースの1つを選択すると、それは私にこの1つの座標(私が問題のケースを識別できるようにする)を返します。私は私のPostItの最後の座標をdragNdrop(実際にはドロップの座標)にすることもできます。私がしたいことは、1つのケースに1つのPostItをドロップすると、ドロップの座標をクリックしてシミュレートし、どのケースでPostItをドロップしたかを表示します。 – Kokodelo

+0

クリックしてメソッドを呼びたいのですか? –

答えて

0

私の問題を解決する方法はここにあります。最初は、postItのdragNdropを処理するメソッドがpostIt.mにありました。そこで私はviewController.mにそれを移しました。今、このメソッドから、私はviewControllerのCollectionViewをピックアップし、クリックを "シミュレート"できます。あなたが正確に何をしたいのか

-(IBAction)handlePan:(UIPanGestureRecognizer *)recognizer{ 
CGPoint translation = [recognizer translationInView:self.view]; 
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y); 

//the coordinates of the drop 
if(recognizer.state == UIGestureRecognizerStateEnded){ 
    CGPoint centerPointOfView = [recognizer locationInView:self.view]; 
    NSLog(@"X - %f, Y - %f",centerPointOfView.x,centerPointOfView.y); 

    //Here is how I pick up the cell where the post it has been dropped 
    [_collectionView cellForItemAtIndexPath:[_collectionView indexPathForItemAtPoint:centerPointOfView]]; 

    NSIndexPath *indexPath =[_collectionView indexPathForItemAtPoint:centerPointOfView]; 

//some log tests 
    NSLog(@"SELECTED: %ld.%ld ", (long)indexPath.section, (long)indexPath.row); 
} 


[recognizer setTranslation:CGPointMake(0, 0) inView:self.view]; 
} 
関連する問題