Skip to content

Commit

Permalink
Adds ability to respond to orientation changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
soberman committed Jan 24, 2016
1 parent c50d1d4 commit bcb7433
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 0 deletions.
113 changes: 113 additions & 0 deletions ARSLineProgress.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
Pod::Spec.new do |s|

s.name = "ARSPopover"
s.version = "2.2.1"
s.summary = "Universal popover for iPhone and iPad."

s.description = <<-DESC
# ARSPopover
Universal popover for iPhone and iPad that you can use in your projects. No custom drawing, no custom elements - everything is purely native.
| iPhone | iPad |
| ---------------------------- | ------------------------ |
| ![ARSPopover-iPhone][iPhone] | ![ARSPopover-iPad][iPad] |
[iPhone]: http://git.arsenkin.com/ARSPopover-iPhone.gif
[iPad]: http://git.arsenkin.com/ARSPopover-iPad.gif
## Installation
### CocoaPods
To install with [CocoaPods](http://cocoapods.org/), copy and paste this in your *.pod* file:
platform :ios, '8.3'
pod 'ARSPopover', '~> 2.0'
### Non-CocoaPods way
You can always to do the old way - just drag the source files into your projects and you are good to go.
## Usage
Sample usage of the ARSPopover might look like this:
``` objective-c
- (IBAction)showPopoverWithWebView:(id)sender {
ARSPopover *popoverController = [ARSPopover new];
popoverController.sourceView = self.buttonWithWebView;
popoverController.sourceRect = CGRectMake(CGRectGetMidX(self.buttonWithWebView.bounds), CGRectGetMaxY(self.buttonWithWebView.bounds), 0, 0);
popoverController.contentSize = CGSizeMake(400, 600);
popoverController.arrowDirection = UIPopoverArrowDirectionUp;
[self presentViewController:popoverController animated:YES completion:^{
[popoverController insertContentIntoPopover:^(ARSPopover *popover, CGSize popoverPresentedSize, CGFloat popoverArrowHeight) {
CGFloat originX = 0;
CGFloat originY = 0;
CGFloat width = popoverPresentedSize.width;
CGFloat height = popoverPresentedSize.height - popoverArrowHeight;
CGRect frame = CGRectMake(originX, originY, width, height);
UIWebView *webView = [[UIWebView alloc] initWithFrame:frame];
webView.scalesPageToFit = YES;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]];
[popover.view addSubview:webView];
}];
}];
}
```
### Required properties' configurations
In order to get a working popover, you need to specify next properties:
* `popoverController.sourceView` - The view containing the anchor rectangle for the popover.
``` objective-c
popoverController.sourceView = self.buttonWithWebView;
```
* `popoverController.sourceRect` - The rectangle in the specified view in which to anchor the popover.
``` objective-c
popoverController.sourceRect = CGRectMake(CGRectGetMidX(self.buttonWithWebView.bounds), CGRectGetMaxY(self.buttonWithWebView.bounds), 0, 0);
```
* `popoverController.contentSize` - The preferred size for the popover’s view.
``` objective-c
popoverController.contentSize = CGSizeMake(400, 600);
```
* And the last, most important thing - you have to call method `insertContentIntoPopover` and pass a block of code, which should add subviews to popover's view you wish to see.
_Be sure to call this method only after you have presented popup. Otherwise you might get wrong size in popoverPresentedSize._
``` objective-c
[popoverController insertContentIntoPopover:^(ARSPopover *popover, CGSize popoverPresentedSize, CGFloat popoverArrowHeight) {
CGFloat originX = 0;
CGFloat originY = 0;
CGFloat width = popoverPresentedSize.width;
CGFloat height = popoverPresentedSize.height - popoverArrowHeight;
CGRect frame = CGRectMake(originX, originY, width, height);
UIWebView *webView = [[UIWebView alloc] initWithFrame:frame];
webView.scalesPageToFit = YES;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]];
[popover.view addSubview:webView];
}];
```
## License
ARSPopover is released under the [MIT license](http://opensource.org/licenses/MIT). See LICENSE for details.
DESC

s.homepage = "https://github.com/soberman/ARSPopover"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Yarik Arsenkin" => "info@arsenkin.com" }
s.social_media_url = "http://twitter.com/Soberman777"
s.platform = :ios, "8.3"
s.source = { :git => "https://github.com/soberman/ARSPopover.git", :tag => "2.2.1" }
s.source_files = "Source/ARSPopover.{h,m}"
s.exclude_files = "Demo/*"
s.public_header_files = "Source/ARSPopover.h"
s.requires_arc = true

end
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2016 Yaroslav Arsenkin (http://arsenkin.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ARSPopover
Universal popover for iPhone and iPad that you can use in your projects. No custom drawing, no custom elements - everything is purely native.

| iPhone | iPad |
| ---------------------------- | ------------------------ |
| ![ARSPopover-iPhone][iPhone] | ![ARSPopover-iPad][iPad] |

[iPhone]: http://git.arsenkin.com/ARSPopover-iPhone.gif
[iPad]: http://git.arsenkin.com/ARSPopover-iPad.gif

## Installation

### CocoaPods
To install with [CocoaPods](http://cocoapods.org/), copy and paste this in your *Podfile* file:

platform :ios, '8.3'
pod 'ARSLineProgress', '~> 1.0'

### Non-CocoaPods way
You can always to do the old way - just drag the source file into your projects and you are good to go.

## Usage

## License
ARSLineProgress is released under the [MIT license](http://opensource.org/licenses/MIT). See LICENSE for details.
46 changes: 46 additions & 0 deletions Source/ARSLineProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ private typealias config = ARSLineProgressConfiguration
@objc private protocol Loader {
var backgroundView: UIVisualEffectView { get set }
optional func hideWithCompletionBlock(block: (() -> Void)?)
optional weak var targetView: UIView? { get set }
}

private enum LoaderType {
Expand Down Expand Up @@ -215,9 +216,30 @@ private final class InfiniteLoader: Loader {
var outerCircle = CAShapeLayer()
var middleCircle = CAShapeLayer()
var innerCircle = CAShapeLayer()
@objc weak var targetView: UIView?

init() {
backgroundView = BlurredBackgroundRect().view
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "orientationChanged:",
name: UIDeviceOrientationDidChangeNotification,
object: nil)
}

deinit {
NSNotificationCenter.defaultCenter().removeObserver(self,
name: UIDeviceOrientationDidChangeNotification,
object: nil)
}

@objc func orientationChanged(notification: NSNotification) {
if let loader = currentLoader {
if let targetView = loader.targetView {
createdFrameForBackgroundView(loader.backgroundView, onView: targetView)
} else {
createdFrameForBackgroundView(loader.backgroundView, onView: nil)
}
}
}

}
Expand All @@ -227,6 +249,8 @@ private extension InfiniteLoader {
func showOnView(view: UIView?, completionBlock: (() -> Void)?) {
if createdFrameForBackgroundView(backgroundView, onView: view) == false { return }

targetView = view

createCircles(outerCircle: outerCircle,
middleCircle: middleCircle,
innerCircle: innerCircle,
Expand Down Expand Up @@ -257,10 +281,31 @@ private final class ProgressLoader: Loader {
var progress: NSProgress?
var failed = false
static weak var weakSelf: ProgressLoader?
@objc weak var targetView: UIView?

init() {
backgroundView = BlurredBackgroundRect().view
ProgressLoader.weakSelf = self
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "orientationChanged:",
name: UIDeviceOrientationDidChangeNotification,
object: nil)
}

deinit {
NSNotificationCenter.defaultCenter().removeObserver(self,
name: UIDeviceOrientationDidChangeNotification,
object: nil)
}

@objc func orientationChanged(notification: NSNotification) {
if let loader = currentLoader {
if let targetView = loader.targetView {
createdFrameForBackgroundView(loader.backgroundView, onView: targetView)
} else {
createdFrameForBackgroundView(loader.backgroundView, onView: nil)
}
}
}

}
Expand All @@ -274,6 +319,7 @@ private extension ProgressLoader {
if let progress = progress { self.progress = progress }

currentCompletionBlock = completionBlock
targetView = view

createCircles(outerCircle: outerCircle,
middleCircle: middleCircle,
Expand Down

0 comments on commit bcb7433

Please sign in to comment.