2016-05-17 3 views
0

私はスクロール可能な "フラッシュカード"のリストをロードするために@Nick LookwoodのiCarouselを使用しています。iCarouselの特定のビューをタップ/選択するにはどうすればいいですか?

iCarouselコントロールの各ビューは1つのフラッシュカードです。設計上、ユーザーがフラッシュカード(ビュー)をタップすると、フラッシュカードが裏返しになることが必要です。 iCarouselを使用する前に、フロント用とバック用の2つの独立したコントロールを作成していましたが、UIView.Transition(すばらしいFlip From Topアニメーション)を使用して、Tapが検出されたときに前後に移動しました。円形。

UITapGestureRecognizerをビューに追加すると、不自然なアーティファクトが発生し、期待どおりに機能しなくなります(オーバーラップするコントロール、現在のフリッピングの代わりに次のコントロール、アニメーションなどがありません)。 Tap Gesture Recognizerの代わりにiCarousel DelegateでSelectedイベントを使用すると便利ですが、私はそこで正確に何をしますか?

具体的なビューを置き換えたいと思いますが、は別のタップで表示されましたが、再利用可能なビューのアイデア全体と矛盾していると感じています。私は何もできませんか? (画面が画面外になったら、もう一度「前にめちゃくちゃ」と表示されます)

ありがとう!

p

P.S.私はC#とXamarin.iOSを使用していますが、Obj-CとSwiftコードはかなりよく理解できますので、どんな助けもありがとうございます。

+0

iCarouselは、提供されたビューを再利用するかどうかを気にしません。ビューを選択したときにアニメーションをトリガーすることはできませんか? – Paulw11

答えて

0

iCarausalには多くの例があります。

iCarausal

、具体的に、フォルダ名 "基本的なiOSの例"

どのようにデリゲートメソッドで以下の変更について:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view 
{ 
    UILabel *label = nil; 

    //create new view if no view is available for recycling 
    if (view == nil) 
    { 
     //don't do anything specific to the index within 
     //this `if (view == nil) {...}` statement because the view will be 
     //recycled and used with other index values later 
     view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)]; 
     ((UIImageView *)view).image = [UIImage imageNamed:@"page.png"]; 
     view.contentMode = UIViewContentModeCenter; 

     //back view i have just added this apart from it there is no change made by me in this method 
     UIView *backView = [[UIView alloc] initWithFrame:view.bounds]; 
     backView.tag = 2; 
     [backView setBackgroundColor:[UIColor redColor]]; 
     [view addSubview:backView]; 
     [backView setHidden:YES]; 
     //back view 

     label = [[UILabel alloc] initWithFrame:view.bounds]; 
     label.backgroundColor = [UIColor clearColor]; 
     label.textAlignment = NSTextAlignmentCenter; 
     label.font = [label.font fontWithSize:50]; 
     label.tag = 1; 
     [view addSubview:label]; 



    } 
    else 
    { 
     //get a reference to the label in the recycled view 
     label = (UILabel *)[view viewWithTag:1]; 
    } 

    //set item label 
    //remember to always set any properties of your carousel item 
    //views outside of the `if (view == nil) {...}` check otherwise 
    //you'll get weird issues with carousel item content appearing 
    //in the wrong place in the carousel 
    label.text = [_items[index] stringValue]; 

    return view; 
} 

とdidSelectを実装し、私はあなたがこれを使用していると仮定します委任者:

- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index{ 

    UIView *frontview = [carousel itemViewAtIndex:index]; 
    UIView *backView = [frontview viewWithTag:2]; 

    BOOL isInFront = NO; 

    if (backView.hidden == NO) { 
     isInFront = YES; 
    } 
    [UIView transitionWithView: isInFront ? backView : frontview 
         duration:1.0 
         options:UIViewAnimationOptionTransitionFlipFromLeft 
        animations:^{ 
         [backView setHidden:isInFront]; 
        } 
        completion:nil]; 

} 

コードをもっと構造化して書く必要があります。これはiCarausalで必要なものを達成できることを示す例です。

関連する問題