0
Im正在使用SwipeGestureRecognizer。 它按照我的預期工作,但是當我在模擬器中退出應用程序並再次運行它時,SwipeGestureRecognizer不再響應。如果我退出iOS模擬器後再次運行它,它可以工作。在Ios Simulator中重新啓動應用程序時,swipeGestureRecognizer無法正常工作
這是我曾嘗試:
#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);
}