0
我想創建UIImage的滑塊,可以放大圖像並滑動到其他圖像。 我的刷卡不被識別,我不知道爲什麼。 我使用可可豆莢,如果你知道一個豆莢是誰做的,請告訴我。 或者,是否有可能在照片庫中使用iPhone的代碼?在ui滾動視圖中沒有手勢識別器uiimageview
這是我的代碼:
- (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");
}
}
非常感謝。 是否有可能使用UiPageViewController縮放? 我嘗試將我的scrollView1放入其他scrollViewTop,並在scrollViewTop上添加滑動手勢,但它不起作用... – Malicia
不要添加滑動手勢...這是滾動視圖。它將滾動。 –