そのUICollectionView
ため、ユーザーがピンチアウトまたはピンチインして、コレクションセルを展開および折りたたむことができるようにしたいと考えています。このチュートリアルを使用して、ビットの展開と折りたたみを実行しました。これは機能します。次に、以下のコードをcollectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
デリゲート メソッドに追加しました。
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchCollection:)];
[cell addGestureRecognizer:pinchGesture];
pinchCollection:
次に、次のようなアクションを作成しました。
-(void)pinchCollection:(id)sender {
UIPinchGestureRecognizer *gesture = (UIPinchGestureRecognizer*)sender;
if (gesture.state == UIGestureRecognizerStateBegan) {
if (gesture.scale <= -1) { // I also changed this to be gesture.scale < 1 but it didn't work.
// pinch in
[self collapseCollection];
gesture.scale = 1;
}
if (gesture.scale >= 1) { // I changed this to be gesture.scale > 1 but it didn't work either.
// pinch out
[self expandCollection];
gesture.scale = -1;
}
}
}
ただし、ピンチアウトコードのみが機能します。これを適切に行う方法を参照するチュートリアルまたはコードを検索しましたが、うまくいきませんでした。
コレクションの展開は次のようになります。