gpt4 book ai didi

ios - while语句,不在动画中拍摄相同的图像

转载 作者:行者123 更新时间:2023-11-29 03:38:51 25 4
gpt4 key购买 nike

我需要一些帮助来制作 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 中创建 while 循环

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

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

关于ios - while语句,不在动画中拍摄相同的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18760724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com