我正在尝试模仿所有设备(如Instagram)的3D触摸查看和弹出 - 所以显示偷看并弹出一个长按手势。这可能吗?我发现PeekView但到目前为止,我发现无法将其与我的Objective C应用程序(它在Swift中)合并。
目前我已经复制了PeekView项目 - 我有一个包含几个单元格的集合视图,每个单元格中都有一个图像。
@property (nonatomic, strong) UILongPressGestureRecognizer *longPress;
- (PhotoCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
PhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kPhotoCell forIndexPath:indexPath];
cell.image.image = [UIImage imageNamed:@"image1"];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(nonnull UICollectionViewCell *)cell forItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
self.longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGestures:)];
self.longPress.minimumPressDuration = 1.0f;
self.longPress.allowableMovement = 100.0f;
[cell addGestureRecognizer:self.longPress];
}
现在我正在尝试实现handleLongPressGestures
方法,但由于下面显示的错误,我无法使用PeekView方法。
编辑:
因此,当尝试使用示例中显示的viewForController
方法时,如果我添加@objc
,则会抱怨选项部分。有解决方法吗?
public enum PeekViewActionStyle : Int {
case Default
case Selected
case Destructive
}
public struct PeekViewAction {
var title: String
var style: PeekViewActionStyle
}
public class PeekView: UIView {
var shouldToggleHidingStatusBar = false
var contentView: UIView?
var buttonHolderView: UIView?
var completionHandler: (Int -> Void)?
var arrowImageView: UIImageView!
public class func viewForController(
parentViewController parentController: UIViewController,
contentViewController contentController: UIViewController,
expectedContentViewFrame frame: CGRect,
fromGesture gesture: UILongPressGestureRecognizer,
shouldHideStatusBar flag: Bool,
withOptions menuOptions: [PeekViewAction]?=nil,
completionHandler handler: (Int -> Void)?=nil) {
...
答案 0 :(得分:1)
库的问题是Swift struct
无法桥接到Objective-C
,因此您无法创建PeekViewAction
数组。我已经使用Obj-C支持更新了代码,所以现在您可以使用另一个静态方法来显示PeekView
。用法如下:
NSArray *options = @[@{@"Option 1": @(PeekViewActionStyleDefault)},
@{@"Option 2": @(PeekViewActionStyleDestructive)}];
UIViewController *contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"previewVC"];
[PeekView viewForControllerWithParentViewController:self
contentViewController:contentViewController
expectedContentViewFrame:CGRectMake(0, 0, 280, 400)
fromGesture:gesture
shouldHideStatusBar:YES
withOptions:options
completionHandler:nil];
确保下载最新版本的库。感谢您使用PeekView
,如果还有任何其他问题,请报告回来:)