Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios While语句,在动画中不拍摄相同的图像_Ios_Objective C_While Loop - Fatal编程技术网

Ios While语句,在动画中不拍摄相同的图像

Ios While语句,在动画中不拍摄相同的图像,ios,objective-c,while-loop,Ios,Objective C,While Loop,我需要一些帮助来制作while语句。我的动画中有不同的图像。 但是我不想在动画之后显示相同的图像 它现在的工作原理:image1显示->image3显示->image3显示 我希望它永远是一个新的形象显示 - (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; int interval = 5+(arc4random() % 6); int section = 0; int row = (arc4rando

我需要一些帮助来制作
while语句
。我的动画中有不同的图像。 但是我不想在动画之后显示相同的图像

它现在的工作原理:image1显示->image3显示->image3显示

我希望它永远是一个新的形象显示

- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];


int interval = 5+(arc4random() % 6);

int section = 0;
int row = (arc4random() % self.jsonDict.count);


NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
[NSTimer scheduledTimerWithTimeInterval:interval
                                 target:self
                               selector:@selector(updateCells:)
                               userInfo:indexPath
                                repeats:NO];

    NSLog(@"seconds: %d", interval);
    NSLog(@"row: %d", row);}



- (void)updateCells:(NSTimer *)timer {



NSIndexPath *indexPath = [timer userInfo];
NSObject *obj = [_jsonDict objectAtIndex:indexPath.row];
NSLog(@"array: %@", obj);

UIImage *img = [self randomImageWithObject:obj];

NSString *title = [obj valueForKey:@"title"];
NSLog(@"array: %@", title);

CollectionCell *cell = (CollectionCell *)[self.collectionView cellForItemAtIndexPath:indexPath];

[UIView transitionWithView:cell
                  duration:1.0f
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                animations:^{
                   cell.collectionImageView.image = img;
                } completion:nil];



int interval = 5+(arc4random() % 6);
int section = 0;
int row = (arc4random() % [_jsonDict count]);

NSLog(@"speedeee: %d", interval);
NSLog(@"row: %d", row);

NSIndexPath *indexPath2 = [NSIndexPath indexPathForRow:row inSection:section];



//CollectionCell *newCell = (CollectionCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
[NSTimer scheduledTimerWithTimeInterval:interval
                                 target:self
                               selector:@selector(updateCells:)
                               userInfo:indexPath2
                                repeats:NO];}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return [_jsonDict count];}-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{


CollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ReuseID" forIndexPath:indexPath];

NSObject *obj = [_jsonDict objectAtIndex:indexPath.row];

//NSLog(@"object: %@", obj);

NSArray *images = [obj valueForKey:@"images"];
NSString *imageName = images[0];
//NSLog(@"name: %@", imageName);

cell.collectionImageView.image = [UIImage imageNamed:imageName];


[self cellTitleAndBackground:cell indexPath:indexPath];

return cell;}

- (UIImage *)randomImageWithObject:(NSObject *)obj{
// Random image for cells



NSArray *images = [obj valueForKey:@"images"];
NSInteger randomNumber = arc4random() % [images count];

return [UIImage imageNamed:[images objectAtIndex:randomNumber]];}

我的东西你想要继续动画,然后不需要创建而在ios循环

在UIImageView中有一些属性,可以这样使用

UIImageView *imageView ;
NSArray *imagesArray ;
[imageView setAnimationImages:imagesArray];
[imageView setAnimationDuration:time];
[imageView setAnimationRepeatCount:count];

对于收集,您应使用:

indexPath.item
而不是

indexPath.row
在此处阅读更多信息(表格视图的行,集合视图的项):


使用
while
语句几乎肯定是错误的,因为它听起来好像会阻塞UI线程。您需要使用完成块或类似的东西并保持状态,以便知道下一步要启动的操作。粘贴您正在使用的一些示例代码将有巨大的帮助添加一些我的代码以向您展示@格泽戈尔兹克鲁科夫斯基