ECSlidingViewController の使用中にスワイプして削除すると問題が発生することがわかりました。iOS7の前に、私はこのトリックを使用します:
#pragma mark - SwipeToDelete+SwipeMenu trick
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
return YES;
}
しかし今、これはうまくいきません。
公式の git リポジトリからサンプル プロジェクトをダウンロードし、問題を示すために設定テーブル ビュー コントローラーを変更します。
#import "MESettingsViewController.h"
#import "MEDynamicTransition.h"
#import "UIViewController+ECSlidingViewController.h"
@interface MESettingsViewController ()
@property (nonatomic, strong) UIPanGestureRecognizer *dynamicTransitionPanGesture;
@end
@implementation MESettingsViewController
NSMutableArray *objects;
- (void)viewDidLoad
{
[super viewDidLoad];
objects = [[NSMutableArray alloc] init];
[objects addObject:@"the"];
[objects addObject:@"world"];
[objects addObject:@"is"];
[objects addObject:@"mine"];
[self.tableView reloadData];
}
#pragma mark - UIViewController
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if ([(NSObject *)self.slidingViewController.delegate isKindOfClass:[MEDynamicTransition class]]) {
MEDynamicTransition *dynamicTransition = (MEDynamicTransition *)self.slidingViewController.delegate;
if (!self.dynamicTransitionPanGesture) {
self.dynamicTransitionPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:dynamicTransition action:@selector(handlePanGesture:)];
}
[self.navigationController.view removeGestureRecognizer:self.slidingViewController.panGesture];
[self.navigationController.view addGestureRecognizer:self.dynamicTransitionPanGesture];
} else {
[self.navigationController.view removeGestureRecognizer:self.dynamicTransitionPanGesture];
[self.navigationController.view addGestureRecognizer:self.slidingViewController.panGesture];
}
}
#pragma mark - IBActions
- (IBAction)menuButtonTapped:(id)sender {
[self.slidingViewController anchorTopViewToRightAnimated:YES];
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return objects.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [objects objectAtIndex:indexPath.row];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[objects removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
#pragma mark - SwipeToDelete+SwipeMenu trick
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
return YES;
}
@end
このコードをコピーして MESettingsViewController.m に貼り付け、アプリケーションを実行し、[設定] メニュー項目に切り替えて、スワイプして削除してみてください。うまくいきません。
修正を手伝ってください。