【发布时间】:2013-05-15 09:02:02
【问题描述】:
我想滑动我的图像视图,但没有切换到左侧。 我从前卡数组中获取图像。我想在 imageview 中显示并垂直滑动。
我试过这个
FrontsCards =[[NSMutableArray alloc]initWithCapacity:9];
[FrontsCards insertObject:@"cloub1.png" atIndex:0];
[FrontsCards insertObject:@"cloub2.png" atIndex:1];
[FrontsCards insertObject:@"cloub3.png" atIndex:2];
[FrontsCards insertObject:@"cloub4.png" atIndex:3];
[FrontsCards insertObject:@"cloub5.png" atIndex:4];
[FrontsCards insertObject:@"cloub6.png" atIndex:5];
[FrontsCards insertObject:@"cloub7.png" atIndex:6];
[FrontsCards insertObject:@"cloub8.png" atIndex:7];
[FrontsCards insertObject:@"cloub9.png" atIndex:8];
- (void)viewDidLoad {
[super viewDidLoad];
UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeHandle:)];
leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[leftRecognizer setNumberOfTouchesRequired:1];
[ImgView addGestureRecognizer:leftRecognizer];
}
- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
int m = 0;
NSLog(@"Left Swipe");
AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
NSLog(@"%d",m);
for(m=0; m<[delegate.FrontsCards count];m++) {
int randIdx=arc4random()%[delegate.FrontsCards count]; // Randomly shufffled
ImgView.userInteractionEnabled=YES;
ImgView.image=[UIImage imageNamed:[delegate.FrontsCards objectAtIndex:randIdx]];
NSLog(@"%d",m);
}
}
图像未交换到 imageview。 如何解决我的问题帮助我解决这个问题。 提前致谢。
【问题讨论】:
-
控制台是否显示来自 leftSwipeHandle: 方法的日志?
-
是否调用了
leftSwipeHandle方法,你检查断点了吗 -
UIImageView 默认禁用 userInteraction,你需要明确设置为 YES。
-
我做了所有这些事情,但图像不会显示。并调用了我的 leftSwipeHandle 方法。
-
@JitendraDeore :
leftSwipeHandle中的 for 循环有什么用。数组中有 9 个元素,并且您使用随机数作为图像,因此最后一张图像将显示在图像视图中。所以我认为不需要那个 for 循环。
标签: ios objective-c uiswipegesturerecognizer