我疯了为什么下面的代码不起作用......
我有一个带有 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