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

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...
Data Type And Storage And Keywords To store data inside the computer we need to first identify the type of data elements we need in our program. There are several different types of dat...
Java If-else Statement Java If-else Statement The Java if statement is used to test the condition. It checks boolean condition: true or false. For example, if a number i...
Asset Color Catalog | Swift Tutorial Asset Color Catalog is the feature of XCode 9. BY the use of this feature we can maintain the colors easily and avoid the mistakes. We can create the ...
Control Flow Statements | Swift tutorial Control Flow : Swift tutorial Swift Provides diffrent type of controll flow statements like: Loops Statements : Loops are used for perform the t...
Introduction to JVM Introduction to JVM JVM stands for Java Virtual Machine. It works as an engine that derives the Java Code. The JVM does not understand Java ty...

Leave a Reply

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