0

私はみんな、

画像を含む NSArray があり、(iPhone フォト ライブラリのように) 左または右にパンして、ある画像から別の画像に渡すことができません。私の写真の配列は、コレクション ビューから取得されます。最初に表示される画像は、コレクション ビューで選択した画像です。

今のところ、右の画像を表示して、この画像を左右に移動することはできますが、他の画像を表示する方法がわかりません。画像が私のビューで 50% 以上になると、中央に移動します。

どうもありがとう。

これが私のコードです:

- (void)viewDidLoad
{
    [super viewDidLoad];

    //NSLog(@"%i", _indexPhoto);

    self.photoImageView.image = [UIImage imageNamed:[_photosCollectionArray objectAtIndex:_indexPhoto]];


    UIPanGestureRecognizer *recognizer;
    recognizer = [[UIPanGestureRecognizer alloc]initWithTarget: self action: @selector(panGestureHandle:)];

    [recognizer setMinimumNumberOfTouches:1];
    [recognizer setMaximumNumberOfTouches:1];
    [[self view] addGestureRecognizer:recognizer];

}


-(void) panGestureHandle:(UIPanGestureRecognizer *) sender {

    NSLog(@"Pan Gesture Handling");
    UIPanGestureRecognizer *pangesture = (UIPanGestureRecognizer *)sender;
    CGPoint translation = [pangesture translationInView:self.view];

    CGPoint imageViewPosition = _photoImageView.center;
    imageViewPosition.x += translation.x;

    _photoImageView.center = imageViewPosition;
    [pangesture setTranslation:CGPointMake(0, 0) inView:self.view];

}
4

4 に答える 4

0

最も簡単な方法UIPanGestureRecognizerは、ビューを .xml ファイルに直接使用または配置することUIScrollViewです。

次に、ユーザーがいつドラッグを停止したかを確認します (例: delegate on UIScrollView)。彼が十分にスクロールした場合は、ビューを開いた位置にアニメーション化し、それ以外の場合はベース位置にアニメーション化します。

于 2013-05-21T15:17:22.703 に答える
0
try to add `CATransition` to your view

最初にスワイプジェスチャーを追加します

    UISwipeGestureRecognizer *recognizer;

recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeLeft:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[contentView addGestureRecognizer:recognizer];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeRight:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[contentView addGestureRecognizer:recognizer];

ハンドルスワイプ

-(void)handleSwipeLeft:(UISwipeGestureRecognizer *)sender{
    CATransition *transition = [CATransition animation];
    transition.duration = 0.3;
    transition.type = kCATransitionPush;
    transition.subtype=kCATransitionFromRight;
    [contentView.layer addAnimation:transition forKey:nil];

}

 -(void)handleSwipeRight:(UISwipeGestureRecognizer *)sender{  

    CATransition *transition = [CATransition animation];
    transition.duration = 0.3;
    transition.type = kCATransitionPush;
    transition.subtype=kCATransitionFromLeft;
    [contentView.layer addAnimation:transition forKey:nil];

}

追加することを忘れないでください#import <QuartzCore/QuartzCore.h>

于 2013-05-22T05:28:52.600 に答える