【问题标题】:iOS 3D Touch Peek/Pop without Storyboards没有故事板的 iOS 3D Touch Peek/Pop
【发布时间】:2017-07-16 20:50:08
【问题描述】:

我正在尝试让 peek/pop 在非故事板 Objective-C 项目上工作,并且我不断获得白色背景而不是模糊背景。我在模拟器和 iPhone 上都试过了。

- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location{
if ([self.presentedViewController isKindOfClass:[LoadTreatmentDetailViewController class]]) {
    return nil;
}

NSIndexPath *indexPath = [self.loadTreatmentsTableView indexPathForRowAtPoint:location];

if(indexPath){
    AllTreatmentsTableViewCell *tableCell = [self.loadTreatmentsTableView cellForRowAtIndexPath:indexPath];

    if(tableCell.treatment){
        LoadTreatmentDetailViewController *previewController = [[LoadTreatmentDetailViewController alloc] initWithTreatment:tableCell.treatment withContext:self.context];
        if(previewController){
            previewController.preferredContentSize = CGSizeMake(0.0, 0.0);
            previewingContext.sourceRect = tableCell.frame;

            return previewController;
        }
    }
}
return nil;
}

- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit{
[self presentViewController:viewControllerToCommit animated:YES completion:nil];
}

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
if([self isForceTouchAvailable]){
    if(!self.previewingContext){
        self.previewingContext = [self registerForPreviewingWithDelegate:self sourceView:self.view];
    }
}else{
    if(self.previewingContext){
        [self unregisterForPreviewingWithContext:self.previewingContext];
        self.previewingContext = nil;
    }
}
}

- (BOOL)isForceTouchAvailable {
BOOL isForceTouchAvailable = NO;
if([self.traitCollection respondsToSelector:@selector(forceTouchCapability)]){
    isForceTouchAvailable = self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable;
}
return isForceTouchAvailable;
}

有可能吗?

感谢您的帮助!

【问题讨论】:

  • 我认为部分问题是我在应用程序中有一些 UIAppearance 代码
  • 有些模糊,但仍然是白色背景,第一次按下时我看不到 tableviewcell。

标签: ios 3d touch peek


【解决方案1】:

这是我用于 Scrollview 的 UIApperance。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-23
    • 1970-01-01
    相关资源
    最近更新 更多