添加到Project
中的图像数组成像是UIImageView
,imagg是Image
由用户选择其默认值
_imaging.image = imagg;
arr = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1.jpg"],
[UIImage imageNamed:@"2.jpeg"],
[UIImage imageNamed:@"3.jpeg"],
[UIImage imageNamed:@"4.jpeg"],
[UIImage imageNamed:@"5.jpeg"],
nil];
假设用户选择了第三张图像,即3.jpeg我在imageview中显示3.jpeg。然后分别使用两个按钮操作Next
和Previous
下一个或上一个图像3.jpeg应该显示。
- (IBAction)previous:(id)sender {
////
}
- (IBAction)next:(id)sender {
//////
}
}
对于下一个动作,它从第2个图像开始,即使是之前的动作也是从第1个图像开始。
答案 0 :(得分:1)
点击下一步按钮
在此
中使用此第一组currentIndex之前-(IBAction)next{
if (arr.count > 0) {
currentIndex++;
if (currentIndex > arr.count - 1) {
currentIndex = 0;
}
imageViewObj.image = [arr objectAtIndex:currentIndex];
}
}
on pervious button
-(IBAction)pervious{
if (arr.count > 0) {
currentIndex--;
if (currentIndex <= 0) {
currentIndex = arr.count - 1;
}
imageViewObj.image = [arr objectAtIndex:currentIndex];
}
}
试试这个工作正常
答案 1 :(得分:1)
这是一个简单的概念,这是在静态方法中工作,但工作正常
分配一个全局变量
@property (strong,nonatomic) NSString *imagestr;
- (IBAction)previous:(id)sender {
int str=[imagestr integerValue];
NSLog(@"the int value==%d",str);
switch (str) {
case 0:
_imaging.image=[arr objectAtIndex:4];
imagestr=@"4";
break;
case 1:
_imaging.image=[arr objectAtIndex:0];
imagestr=@"0";
break;
case 2:
_imaging.image=[arr objectAtIndex:1];
imagestr=@"1";
break;
case 3:
_imaging.image=[arr objectAtIndex:2];
imagestr=@"2";
break;
case 4:
_imaging.image=[arr objectAtIndex:3];
imagestr=@"3";
break;
default:
break;
}
}
- (IBAction)next:(id)sender {
int str=[imagestr integerValue];
NSLog(@"the int value==%d",str);
switch (str) {
case 0:
_imaging.image=[arr objectAtIndex:1];
imagestr=@"1";
break;
case 1:
_imaging.image=[arr objectAtIndex:2];
imagestr=@"2";
break;
case 2:
_imaging.image=[arr objectAtIndex:3];
imagestr=@"3";
break;
case 3:
_imaging.image=[arr objectAtIndex:4];
imagestr=@"4";
break;
case 4:
_imaging.image=[arr objectAtIndex:0];
imagestr=@"0";
break;
default:
break;
}
}
答案 2 :(得分:0)
ImageView *image = [arr objectAtIndex:currentIndex]
答案 3 :(得分:0)
初始化视图控制器时,跟踪当前正在查看的图像(例如0),以用作数组索引。
按下next时,增加索引并使用更新的计数从数组中检索图像。
e.g。
- (IBAction)next:(id)sender {
imageCount++;
[myImageView setImage:[UIImage imageNamed:arr[imageCount] ];
}
希望这会有所帮助。 :)