【发布时间】:2014-05-15 08:40:16
【问题描述】:
我想创建一个 UIImage 滑块,可以放大图像并滑动到其他图像。 我的滑动无法识别,我不知道为什么。 我用可可豆荚,如果你知道这样做的豆荚,请告诉我。 或者,是否可以在照片库中使用 iphone 的代码?
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[imgView setUserInteractionEnabled:YES];
[imgView addGestureRecognizer:swipeLeft];
[imgView addGestureRecognizer:swipeRight];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager GET:@"********************/test.json" parameters:nil success:^(AFHTTPRequestOperation *operation, NSArray *responseObject) {
//NSLog(@"URL");
//NSLog(@"JSON: %@", responseObject);
urlArray = responseObject;
//NSLog(@" %@", urlArray);
int i=0;
url = [NSURL URLWithString:[urlArray objectAtIndex:i]];
//NSLog(@"%@", url);
data = [NSData dataWithContentsOfURL:url];
img = [[UIImage alloc] initWithData:data];
[self.view setBackgroundColor:RGB(32,32,32)];
if(orientation == UIInterfaceOrientationPortrait) {
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-44)];
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:scrollView];
self.scrollView = scrollView;
if (img.size.width>img.size.height){
//format d'images paysage
NSLog(@"PORTAIT image paysage");
NSLog(@"%f", img.size.width);
NSLog(@"%f", img.size.height);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.scrollView.frame.size.width+img.size.height, self.scrollView.frame.size.height)];
//imgView.contentMode = UIViewContentModeScaleAspectFit;
imgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.scrollView addSubview:imageView];
self.scrollView.contentSize = imageView.frame.size;
self.imgView = imageView;
[self.imgView setImage:img];
}
if (img.size.height>img.size.width && orientation == UIInterfaceOrientationPortrait){
//format d'images portrait
NSLog(@"PORTAIT image portrait");
NSLog(@"%f", img.size.width);
NSLog(@"%f", img.size.height);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, img.size.height-img.size.width, self.scrollView.frame.size.height)];
//imgView.contentMode = UIViewContentModeScaleAspectFit;
imgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.scrollView addSubview:imageView];
self.scrollView.contentSize = imageView.frame.size;
self.imgView = imageView;
}
if (img.size.height==img.size.width){
//format d'images portrait
NSLog(@"ICI %f", img.size.width);
NSLog(@"%f", img.size.height);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, img.size.width, self.scrollView.frame.size.height)];
//imgView.contentMode = UIViewContentModeScaleAspectFit;
imgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.scrollView addSubview:imageView];
self.scrollView.contentSize = imageView.frame.size;
self.imgView = imageView;
[self.imgView setImage:img];
}
}
} failure:nil];
}
- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe {
if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"Left Swipe");
}
if (swipe.direction == UISwipeGestureRecognizerDirectionRight) {
NSLog(@"Right Swipe");
}
}
【问题讨论】:
标签: ios uiview uigesturerecognizer