UIPopOverPresentationController In Swift

UIPopOverPresentationController

UIPopOverViewController in swift is writen in swift 3.1 and Use the xcode Version 8.3.2.
For use this import the PopOverViewController folder into your project.
For using this file create the instance of PopOverViewC class and inherit the 

1
UIPopoverPresentationControllerDelegate

 :


1
  <span class="hljs-keyword">var</span> itemPopVC = <span class="hljs-type">PopOverViewC</span>()

Add below line of code in your Tapable button function for set the properties of UIPopOverViewController, change the properties


1
2
3
4
5
6
7
<span class="hljs-keyword">self</span>.itemPopVC.modalPresentationStyle = .popover
<span class="hljs-keyword">self</span>.itemPopVC.popoverPresentationController?.barButtonItem = <span class="hljs-keyword">self</span>.navigationItem.rightBarButtonItem
<span class="hljs-keyword">self</span>.itemPopVC.popoverPresentationController?.permittedArrowDirections = .unknown
<span class="hljs-keyword">self</span>.itemPopVC.popoverPresentationController?.delegate = <span class="hljs-keyword">self</span>
<span class="hljs-keyword">self</span>.itemPopVC.popoverPresentationController?.backgroundColor = <span class="hljs-type">UIColor</span>.red
<span class="hljs-keyword">self</span>.itemPopVC.popoverPresentationController?.popoverLayoutMargins = <span class="hljs-type">UIEdgeInsets</span>.<span class="hljs-keyword">init</span>(top: <span class="hljs-number">50.0</span>, <span class="hljs-keyword">left</span>: <span class="hljs-number">100.0</span>, bottom: <span class="hljs-number">0.0</span>, <span class="hljs-keyword">right</span>: <span class="hljs-number">0.0</span>)
<span class="hljs-keyword">self</span>.present(<span class="hljs-keyword">self</span>.itemPopVC, animated: <span class="hljs-literal">true</span>, completion: { <span class="hljs-number">_</span> <span class="hljs-keyword">in</span> })
1
self.itemPopVC.popoverPresentationController?.barButtonItem

 in this pass the tapable bar button, and there is 

1
sourceRect

 also in which
we pass the rect of any button.

For Get the didSelectCell call back add the notification and add these functions:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">tableDidSelected</span><span class="hljs-params">(<span class="hljs-number">_</span> notification: Notification)</span></span>
  {
    <span class="hljs-keyword">var</span> indexpath: <span class="hljs-type">IndexPath</span>? = (notification.object <span class="hljs-keyword">as</span>? <span class="hljs-type">IndexPath</span>)
    <span class="hljs-keyword">self</span>.itemPopVC.dismiss(animated: <span class="hljs-literal">true</span>, completion: { <span class="hljs-number">_</span> <span class="hljs-keyword">in</span> })
  }
 
 
  <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">popoverPresentationControllerShouldDismissPopover</span><span class="hljs-params">(<span class="hljs-number">_</span> popoverPresentationController: UIPopoverPresentationController)</span></span> -&gt; <span class="hljs-type">Bool</span>
  {
    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
  }
 
  <span class="hljs-func"><span class="hljs-keyword">func</span> <span class="hljs-title">adaptivePresentationStyle</span><span class="hljs-params">(<span class="hljs-keyword">for</span> controller: UIPresentationController)</span></span> -&gt; <span class="hljs-type">UIModalPresentationStyle</span>
  {
    <span class="hljs-keyword">return</span> <span class="hljs-type">UIModalPresentationStyle</span>.<span class="hljs-keyword">none</span>
  }

Related Post

How to install flutter | Flutter tutorial Flutter is the google’s mobile app SDK for develop the high-quality native app for iOS and android. We can develop the app by use of DART and javascri...
New Tools for 64-bit Support in Xcode 9.3   New Tools for 64-bit Support in Xcode 9.3 The last macOS release to support 32-bit apps without compromise is macOS High Sierra. Make sure fu...
Navigation Tab Bar in IOS | Swift tutorial Navigation Tab Bar in IOS | Swift tutorial Different Customizing techniques for Navigation bar with storyboard and code 1) Custom NavigationTabBar b...
Java Operators Java Operators An operator is used to perform an operation over one or more operands. It is a character that represents an action, for example * is a...
Create Firebase single Page Website Create firebase single page Website tutorial In this tutorial we are study how to create single page website by the use of firebase hosting its very ...
Continue Statement in JAVA Continue Statement in JAVA Suppose you are working with loops. Sometime it is desirable terminate the loop or skip some statement inside the loop wit...

Leave a Reply

Your email address will not be published. Required fields are marked *

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.