以下のコードが機能しない理由がわかりません...
UIImageView を持つ単純な UIViewController があり、ユーザーが右または左にスワイプした場合に画像を変更したいと考えています。私はiPhone開発に不慣れです。
ありがとう
#import "SummerViewController.h"
@implementation SummerViewController
//@synthesize scroll;
@synthesize imgClothes, images;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)LeftSwiped
{
NSLog(@"swiped left");
imgClothes.image = [UIImage imageNamed:[images objectAtIndex:0]];
}
-(void)RightSwiped
{
NSLog(@"swiped right");
imgClothes.image = [UIImage imageNamed:[images objectAtIndex:1]];
}
- (void)viewDidLoad
{
images = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"1.jpg"],
[UIImage imageNamed:@"2.jpg"], nil];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(LeftSwiped)];
swipeLeft.numberOfTouchesRequired = 1;
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(RightSwiped)];
swipeRight.numberOfTouchesRequired = 1;
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
.h ファイル:
@interface SummerViewController : UIViewController
{
//IBOutlet UIScrollView *scroll;
IBOutlet UIImageView *imgClothes;
NSArray *images;
}
@property (nonatomic, retain) IBOutlet UIImageView *imgClothes;
@property (nonatomic, retain) IBOutlet NSArray *images;
@end