我玩弄 SwipeGestureRecognizer。它按我的预期工作,但是当我在模拟器中退出应用程序并再次运行它时,SwipeGestureRecognizer 不再响应。如果我在退出 iOS 模拟器后再次运行它,它可以工作。
这是我尝试过的:
#import <UIKit/UIKit.h>
@interface swipeTestUI : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
- (IBAction)mangeSwipeControl:(UIGestureRecognizer*)sender;
@end
实现文件:
#import "swipeTestUI.h"
@interface swipeTestUI ()
@end
@implementation swipeTestUI
@synthesize imageView;
int listOfImages = 0;
- (IBAction)mangeSwipeControl:(UIGestureRecognizer *)sender {
NSLog(@"swipe ok");
NSArray *images=[[NSArray alloc]initWithObjects:
@"1.png",
@"2.png",
@"3.png",
@"4.png",
@"5.png",
@"5.png",nil];
UISwipeGestureRecognizerDirection direction = [(UISwipeGestureRecognizer *) sender direction];
switch (direction) {
case UISwipeGestureRecognizerDirectionLeft:
listOfImages++;
break;
case UISwipeGestureRecognizerDirectionRight:
listOfImages--;
break;
default:
break;
}
listOfImages = (listOfImages < 0) ? ([images count] -1):listOfImages % [images count];
imageView.image = [UIImage imageNamed:[images objectAtIndex:listOfImages]];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}