我想创建一个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");
}
}
答案 0 :(得分:0)
UISwipeGestureRecognizer
未被触发,因为您附加的UIImageView位于UIScrollView
内。 UIScrollView
将在UIImageView获取手势之前捕获手势。
执行您提出的建议的最佳方法是将UIImageView
置于其内部UIScrollView
进行缩放,就像您所做的那样,然后将每个UIScrollView
放入其中UIScrollView
。 1}}在一个较大的pagingEnabled
UIScrollView
中。显然,您必须进行一些基本的框架计算,以便将UIScrollView
定位在顶部UIPageViewController
内并设置它的contentSize。
你总是可以使用{{1}},这可能是我要做的。