2014-11-24 71 views
0

我是iOS开发的新手。我想在我的应用程序中做一个应用程序,我做一个UIScrollview和在这个UIScrollView我添加一个UIImageview。当viewDidAppear我喜欢设置为如何通过iOS中的UISwipeGestureRecognizer在ImageView中通过SwipeLeft在ImageView中显示NextImage?

-(void)viewDidAppear:(BOOL)animated 
{ 
NSDictionary *dict=[self.imagesa objectAtIndex:0]; 
NSString *imagelink=[dict valueForKey:@"link"]; 
NSLog(@"imageLink %@",imagelink); 
[self.bigImage sd_setImageWithURL:[NSURL URLWithString:imagelink] placeholderImage:[UIImage imageNamed:@"1.png"]]; 
} 

和代码添加一个手势我的ImageView和Scrollvie等作为

UISwipeGestureRecognizer *swipeGestureLeftdirection=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(slideToLeftWithGestureRecognizer:)]; 
swipeGestureLeftdirection.delegate=self; 
swipeGestureLeftdirection.direction=UISwipeGestureRecognizerDirectionLeft; 
[self.bigImage addGestureRecognizer:swipeGestureLeftdirection]; 
[self.bigScrollview addGestureRecognizer:swipeGestureLeftdirection]; 

UISwipeGestureRecognizer *swipeGestureRightdirection=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(slideToRighttWithGestureRecognizer:)]; 
swipeGestureRightdirection.delegate=self; 
swipeGestureRightdirection.direction=UISwipeGestureRecognizerDirectionRight; 
[self.bigImage addGestureRecognizer:swipeGestureRightdirection]; 
[self.bigScrollview addGestureRecognizer:swipeGestureRightdirection]; 

这里Self.bigimage是我的UIImageView和self.bigScrollview是我的UIScrollView ImageView的图像。 现在我想当用户向左滑动,然后我想UIImageview图像self.imagesa下一个索引和刷卡权然后我想UIImageVIew图像回索引图像如何可能。请给我解决方案。

+0

显示您UISwipeGestureRecognizer行动 – Sport 2014-11-24 06:31:39

+0

@Sport UISwipeGestureRecognizer动作 - (void)slideToLeftWithGestureRecognizer:(UISwipeGestureRecognizer *)gestureReco gnizer {index = 0; index <[self.imagesa count]; index ++) { self.bigImage.image = [self.imagesa objectAtIndex:index + 1]; } } – 2014-11-24 06:35:26

回答

1

做没有用的循环内,slideToLeftWithGestureRecognizer:这样

-(void)slideToLeftWithGestureRecognizer:(UISwipeGestureRecognizer *)gestureRecognizer 
{ 
    if(index<[self.imagesa count]) 
    { 
     NSDictionary *dict=[self.imagesa objectAtIndex:index]; 
     NSString *imagelink=[dict valueForKey:@"link"]; 
     NSLog(@"imageLink %@",imagelink); 
     [self.bigImage sd_setImageWithURL:[NSURL URLWithString:imagelink] placeholderImage:  [UIImage imageNamed:@"1.png"]]; 

    index++; 
    } 
} 

赚指数作为全球vairable

写代码,在viewDidLoad中initailize以0

-(void)slideToRighttWithGestureRecognizer:(UISwipeGestureRecognizer *)gestureRecognizer 
    { 
     if(index>0) 
    { 
     index--; 
     NSDictionary *dict=[self.imagesa objectAtIndex:index]; 
     NSString *imagelink=[dict valueForKey:@"link"]; 
     NSLog(@"imageLink %@",imagelink); 
     [self.bigImage sd_setImageWithURL:[NSURL URLWithString:imagelink] placeholderImage:  [UIImage imageNamed:@"1.png"]]; 


    } 
} 
+0

但在这里我的数组是包含图像的URL链接,所以我写为 NSDictionary * dict = [self.imagesa objectAtIndex:index]; NSString * imagelink = [dict valueForKey:@“link”]; NSLog(@“imageLink%@”,imagelink); [self.bigImage sd_setImageWithURL:[NSURL URLWithString:imagelink] placeholderImage:[UIImage imageNamed:@“1.png”]]; index ++; 但它显示错误行NSDictionary * dict = [self.imagesa objectAtIndex:index]; – 2014-11-24 06:49:01

+0

兄弟,我修改了我的答案,再看一遍,如果这可以帮助你。 – 2014-11-24 06:56:28

+0

在这里我的imageview是在我的滚动视图,所以我添加一个SWipeGesture到我的Imageview,但你的代码不工作,我可以添加一个Swipegesture到我的滚动查看,然后它是工作? – 2014-11-24 07:02:57

相关问题