简体   繁体   English

如何实现这种外观/视图外观?

[英]How to achieve this segue/view appearance?

App Store屏幕截图 In the App Store, multiple app icons are displayed as in this screenshot. 在App Store中,如该屏幕截图所示,将显示多个应用程序图标。

轻按App图标的App Store屏幕截图 On tapping one of the app icons, we get a view that shows us the app details, while dimming the rest of the view. 点击其中一个应用程序图标,我们将得到一个视图,向我们显示应用程序详细信息,同时将其余视图变暗。 Tapping anywhere outside the view, dismisses it. 轻击视图外部的任何位置,将其关闭。

How do I achieve this effect? 如何达到此效果?

From what I have understood, it is not a view controller with a modal or a popover segue. 据我了解,它不是具有模态或弹出窗口序列的视图控制器。 Neither is it a Show or Show Detail segue. 它既不是Show或Show Detail segue。


My guess is that they are doing it by 我的猜测是他们正在这样做

  1. creating someView 创建someView
  2. overlaying a black fullscreen view on screen 1 with 50% opacity 在屏幕1上以50%不透明度覆盖黑色全屏视图
  3. setting someView.hidden = false and positioning it above the translucent layer 设置someView.hidden = false并将其someView.hidden = false在半透明层上方
  4. adding a tap gesture recognizer 'dismissSomeView' which will hide the view again and remove the translucent layer as well 添加点击手势识别器“ dismissSomeView”,它将再次隐藏视图并移除半透明层

Please correct me if I am wrong, and if there is a better/ Apple-approved way to accomplish it. 如果我错了,并且有更好/苹果认可的方法可以解决这个问题,请纠正我。


I am trying to achieve this effect on an iPhone, with support for iOS 8 and 9. 我正在尝试在支持iOS 8和9的iPhone上实现这种效果。

After I posted the question, I found the best answer soon after. 发布问题后,我很快找到了最佳答案。

The above effect is achieved in the following way: 通过以下方式可以达到上述效果:

  1. The App Store main view is considered the presenting view controller . App Store主视图被视为呈现视图控制器

  2. The individual app details is presented in a view with its own view controller. 单个应用程序的详细信息在具有其自己的视图控制器的视图中显示。 This is the presented view controller . 这是提出的视图控制器 The segue is chosen to be Present Modally . 该segue被选择为Present Modally In its own prepareForSegue: method, the presenting view controller sets the transitioning delegate (explained below) of this view controller, and sets the modalPresentationStyle to be .Custom . 在其自己的prepareForSegue:方法,所述呈现视图控制器设置此视图控制器的转变代表(在下面解释),并设置modalPresentationStyle.Custom

  3. The presented view controller has a transitioning delegate object , which conforms to the UIViewControllerTransitioningDelegate protocol. 呈现的视图控制器具有一个过渡委托对象 ,该对象符合UIViewControllerTransitioningDelegate协议。

  4. This delegate has methods which point to a presentation controller and an animator object. 该委托具有指向表示控制器和动画对象的方法。 (details of this step are available below). (此步骤的详细信息在下面提供)。

  5. The custom animator object is a class that conforms to UIViewControllerAnimatedTransitioning protocol. 定制动画器对象是符合UIViewControllerAnimatedTransitioning协议的类。 It determines how the presented view controller is animated in and out of view. 它确定所呈现的视图控制器如何在视图中进行动画处理。

  6. The custom presentation controller (of UIPresentationController class) is the one that determines the size and position of the presented view controller. 自定义表示控制器 (属于UIPresentationController类)是确定所显示的视图控制器的大小和位置的控制器。 It also is in charge of presenting the dimming chrome/view. 它还负责呈现变暗的镶边/视图。 There are option to animate the dimming view along with the transitioning animations of the presented view controller. 可以对调光视图进行动画处理,以及所显示视图控制器的过渡动画。


Step 4 details: The rather wordy method names are presentationControllerForPresentedViewController(_ presented: UIViewController, presentingViewController presenting: UIViewController!, sourceViewController source: UIViewController) -> UIPresentationController? 步骤4的详细信息:相当冗长的方法名称是presentationControllerForPresentedViewController(_ presented: UIViewController, presentingViewController presenting: UIViewController!, sourceViewController source: UIViewController) -> UIPresentationController? and animationControllerForPresentedController(_ presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? animationControllerForPresentedController(_ presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? respectively. 分别。


This link explains it better than I could possibly do it: https://www.shinobicontrols.com/blog/ios8-day-by-day-day-24-presentation-controllers 这个链接比我可能会更好地解释了它: https : //www.shinobicontrols.com/blog/ios8-day-by-day-day-24-presentation-controllers


And for a video tutorial of achieving a similar effect using Presentation Controllers, watch the second half of the video 'A Look Inside Presentation Controllers' from last year's WWDC: https://developer.apple.com/videos/wwdc/2014/ 有关使用Presentation Controllers实现类似效果的视频教程,请观看去年WWDC的视频“ A Look Inside Presentation Controllers”的后半部分: https//developer.apple.com/videos/wwdc/2014/

Build a white CustomedView with white background color in the center. 用中心的白色背景构建一个白色的CustomedView。

Build a UIView with black background, about transparent 70%. 用黑色背景构建一个UIView,大约透明70%。

Add the customedView to maskView, add the maskView to self.view. 将customedView添加到maskView,将maskView添加到self.view。

MyCustomedView *topView = [[MyCustomedView alloc] initWithFrame:CGRectMake(50, 150, self.view.frame.size.width - 100, self.view.frame.size.height - 300)];
[maskView addSubview:topView];

UIView *maskView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
maskView.backgroundColor = [UIColor blackColor];
maskView.alpha = 0.75;
[self.view addSubview:maskView];

When you click one of the icons in the UICollectionViewController, It trigers to do some like things like that. 当您单击UICollectionViewController中的图标之一时,它会尝试执行类似的操作。 and pass some parameter, like name, descriptions. 并传递一些参数,例如名称,说明。

This is just my thought, you can do with your idea. 这只是我的想法,您可以实现自己的想法。 Hope this can help you. 希望这可以帮到你。

Create a segue in the storyboard with the following parameters: 使用以下参数在情节提要中创建序列:

SEGUE: Present Modally SEGUE:以模态呈现

PRESENTATION: Form Sheet 演示文稿:表格

TRANSITION: Default 投影片切换:预设

animates checked 动画检查

Note: This effect is achievable in Ipad. 注意:此效果在Ipad中是可以实现的。 To have similar effect in iphone you need to override trait collection. 要在iPhone中产生类似的效果,您需要覆盖特征收集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM