2

私は、15枚の画像を前面画像として配列に保存し、別の15枚の画像を背面画像として保存するアプリを開発しています。その画像をスクロールビューに垂直に追加したいのですが、それは成功しましたが、今私の問題は、その2つの配列画像をどのように比較できるかということです。

垂直スクロールビューに正面画像を追加すると、正常に追加されましたが、ランダムにシャッフルされませんでした。

この問題を解決するために私を助けてください。

前もって感謝します。

私のコードを確認してください:

- (void)viewDidLoad
{
    [super viewDidLoad];


    AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];

    delegate.front=TRUE;
    delegate.back=FALSE;


    UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];

    [scrollView setPagingEnabled:YES];

    [scrollView setShowsHorizontalScrollIndicator:NO];

    FrontsCards=[[NSMutableArray alloc]initWithObjects:@"cloub1.png",@"cloub2.png",@"cloub3.png",@"cloub4.png",@"cloub5.png",@"cloub6.png",@"cloub7.png",@"cloub8.png",@"cloub9.png",@"cloub10.png",@"cloub11.png",@"cloub12.png",@"diamond1.png",@"diamond2.png",@"diamond3.png",@"diamond4.png",@"diamond5.png", nil];

    for(int m=0; m<[FrontsCards count];m++)
      {
        ImgView.tag=m;

        int randIdx=arc4random()%[FrontsCards count];


        NSString *imageName=[FrontsCards objectAtIndex:randIdx];

    //  NSLog(@"%d",randIdx);


        NSString *fullImageName=[NSString stringWithFormat:@"%@",imageName];

        int padding=25;
        // padding is given.

        CGRect imageViewFrame=CGRectMake(scrollView.frame.size.width*m+padding, scrollView.frame.origin.y, scrollView.frame.size.width-2*padding, scrollView.frame.size.height);

        ImgView=[[UIImageView alloc]initWithFrame:imageViewFrame];

        [ImgView setImage:[UIImage imageNamed:fullImageName]];

        [ImgView setContentMode:UIViewContentModeScaleAspectFill];


        [scrollView addSubview:ImgView];


        UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapImgView:)];
        doubleTap.numberOfTapsRequired = 2;
        doubleTap.delegate = self;

        [self.ImgView addGestureRecognizer:doubleTap];

        self.ImgView.userInteractionEnabled=YES;


    }

    CGSize scrollViewSize=CGSizeMake(scrollView.frame.size.width*[FrontsCards count], scrollView.frame.size.height);
    [scrollView setContentSize:scrollViewSize];
    [self.view addSubview:scrollView];




}


- (void)doubleTapImgView:(UITapGestureRecognizer *)gesture
{


    AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];

    delegate.back=TRUE;

    delegate.front=FALSE;


    NSLog(@"%d", gesture.view.tag);

        NSLog(@"double-tap");

    BackCards =[[NSMutableArray alloc]initWithObjects:@"card1.jpg",@"card2.jpg",@"card3.jpg",@"card4.jpg", nil];

    UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];

    [scrollView setPagingEnabled:YES];

    [scrollView setShowsHorizontalScrollIndicator:NO];

    for(int m=0; m< [BackCards count];m++)
    {       
        NSString *imageName=[BackCards objectAtIndex:m];

        NSString *fullImageName=[NSString stringWithFormat:@"%@",imageName];

        int padding=25;
        // padding is given.

        CGRect imageViewFrame=CGRectMake(scrollView.frame.size.width*m+padding, scrollView.frame.origin.y, scrollView.frame.size.width-2*padding, scrollView.frame.size.height);

        ImgView=[[UIImageView alloc]initWithFrame:imageViewFrame];

        [ImgView setImage:[UIImage imageNamed:fullImageName]];

        [ImgView setContentMode:UIViewContentModeScaleAspectFill];


        [scrollView addSubview:ImgView];


        UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapImgView:)];
        doubleTap.numberOfTapsRequired = 2;
        doubleTap.delegate = self;

        [self.ImgView addGestureRecognizer:doubleTap];

        self.ImgView.userInteractionEnabled=YES;


    }

    CGSize scrollViewSize=CGSizeMake(scrollView.frame.size.width*[FrontsCards count], scrollView.frame.size.height);
    [scrollView setContentSize:scrollViewSize];
    [self.view addSubview:scrollView];

}
4

2 に答える 2