首页 > 技术文章 > iOS collection长按编辑功能

tongyuling 2015-10-16 16:07 原文

//长按是否出现编辑菜单(Cut Copy Paste)

- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath

{

    return YES;

}

 

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender

{

    NSString * selName=NSStringFromSelector(action);

    //菜单中只会出现copy

    if ([selName isEqualToString:@"copy:"]) {

        return YES;

    }

    return NO;

}

 

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender

{

    //可以执行一些拷贝粘贴等操作

    //详细的东西请看 UIPasteboard

    //点击Copy要执行的方法

    NSString * selName=NSStringFromSelector(action);

    NSLog(@"%@",selName);

}

 

推荐阅读