├── .gitignore ├── APNotificationAlertView ├── APNotificationAlertView.swift └── APNotificationAlertViewBaseExtension.swift ├── LICENSE ├── NotificationAlertView.podspec ├── README.md ├── Resource ├── NotificationPopupDialogExample.gif ├── NotificationPopupQuestionExample.gif ├── NotificationPopupStoryboardExample.gif ├── NotificationPopupTextExample.gif └── appus.png └── demo ├── AppusNotificationPopupExample.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── NotificationPopupExample ├── APNotificationAlertView ├── APNotificationAlertView.swift └── APNotificationAlertViewBaseExtension.swift ├── AppDelegate.swift ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json ├── Contents.json ├── Logo.imageset │ ├── Contents.json │ └── logo-1.png └── LogoFront.imageset │ ├── Contents.json │ └── logo_splash@3x.png ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── LabelCollectionViewCell.swift └── ViewController.swift /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | xcshareddata 3 | 4 | xcuserdata 5 | /Gantt (Autosaved).oplx/ 6 | 7 | *.xcuserstate 8 | *.xcbkptlist 9 | *.DS_Store 10 | .project 11 | .settings 12 | .idea 13 | Pods 14 | -------------------------------------------------------------------------------- /APNotificationAlertView/APNotificationAlertView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // APNotificationAlertView.swift 3 | // AppusNotificationPopupExample 4 | // 5 | // Created by Andrey Pervushin on 16.10.15. 6 | // Copyright © 2015 Andrey Pervushin. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | enum APNotificationAlertViewPosition: Int { 12 | 13 | case Top, Bottom, Custom 14 | 15 | } 16 | 17 | class APNotificationAlertView: UIView { 18 | 19 | 20 | static var popup:APNotificationAlertView? 21 | 22 | //May be used in custom popup extensions if you should send some response 23 | //based on some actions 24 | var customCompletionHandler:((Int) -> Void)? 25 | 26 | //Show/hide animation duration in seconds 27 | var animationDuration: CFTimeInterval = 0.5 28 | 29 | //If this value not equal to "0" popup will hide after specified time in 30 | //seconds 31 | var hideAfterDelay: CGFloat = 0 32 | 33 | //View that is showing in popup, you may use it to get any properties from 34 | //your view. (Change it it on your own risk) 35 | var contentView: UIView? 36 | 37 | //Chage this to show popup from top or bottom 38 | var position: APNotificationAlertViewPosition!{ 39 | didSet{ 40 | 41 | switch position! { 42 | case .Top: 43 | self.addTopConstraint() 44 | return 45 | 46 | case .Bottom: 47 | self.addBottomConstraint() 48 | return 49 | 50 | default: 51 | return 52 | } 53 | } 54 | } 55 | 56 | 57 | //Set the value that will be best for your project 58 | var height : CGFloat = 100 { 59 | 60 | didSet{ 61 | 62 | if (self.heightConstraint != nil){ 63 | 64 | self.heightConstraint!.constant = height 65 | 66 | } 67 | } 68 | } 69 | 70 | private var blurView: UIVisualEffectView? 71 | 72 | private var backgroundImageView = UIImageView.init() 73 | 74 | private var frontImageView = UIImageView.init() 75 | 76 | private var heightConstraint:NSLayoutConstraint? 77 | 78 | private var positionConstraint:NSLayoutConstraint? 79 | 80 | private var isOpen = false 81 | 82 | private var isShowing = false 83 | 84 | private var isHiding = false 85 | 86 | private var transformLayer: CATransformLayer? 87 | 88 | 89 | //Construct popup with any specified view. View will fit popup size however 90 | //be carefull with constraints specified in it 91 | static func popupWithView(view:UIView?) -> APNotificationAlertView{ 92 | 93 | //-- Elements 94 | 95 | let tempPopup = APNotificationAlertView() 96 | 97 | tempPopup.contentView = view 98 | 99 | for c in tempPopup.contentView!.constraints { 100 | 101 | if ( c.firstAttribute == .Height || c.firstAttribute == .Width){ 102 | 103 | tempPopup.contentView!.removeConstraint(c) 104 | 105 | } 106 | 107 | } 108 | 109 | tempPopup.hidden = true 110 | 111 | tempPopup.translatesAutoresizingMaskIntoConstraints = false 112 | 113 | tempPopup.backgroundImageView.translatesAutoresizingMaskIntoConstraints = false 114 | 115 | tempPopup.frontImageView.translatesAutoresizingMaskIntoConstraints = false 116 | 117 | tempPopup.transformLayer = CATransformLayer(); 118 | 119 | //-- Blur View 120 | 121 | tempPopup.backgroundColor = UIColor.clearColor() 122 | 123 | let blur = UIBlurEffect(style: UIBlurEffectStyle.Light) 124 | 125 | tempPopup.blurView = UIVisualEffectView(effect: blur) 126 | 127 | tempPopup.blurView!.translatesAutoresizingMaskIntoConstraints = false 128 | 129 | //-- UI relations 130 | 131 | let root = UIApplication.sharedApplication().keyWindow! 132 | 133 | root.addSubview(tempPopup) 134 | 135 | tempPopup.addConstraintsToPopup() 136 | 137 | tempPopup.layer.addSublayer(tempPopup.transformLayer!) 138 | 139 | tempPopup.transformLayer!.addSublayer(tempPopup.backgroundImageView.layer) 140 | 141 | tempPopup.transformLayer!.addSublayer(tempPopup.frontImageView.layer) 142 | 143 | //-- Blur View 144 | 145 | tempPopup.superview!.addSubview(tempPopup.blurView!) 146 | 147 | tempPopup.superview!.insertSubview(tempPopup.blurView!, belowSubview: tempPopup) 148 | 149 | tempPopup.addBlurConstraints() 150 | 151 | return tempPopup 152 | 153 | } 154 | 155 | 156 | 157 | //Use it to show popup once it was constructed and hide previous 158 | func show(){ 159 | 160 | 161 | if (self.contentView != nil){ 162 | 163 | self.contentView!.removeFromSuperview() 164 | 165 | self.contentView!.translatesAutoresizingMaskIntoConstraints = false 166 | 167 | self.addSubview(self.contentView!) 168 | 169 | APNotificationAlertView.addMarginConstraints(self, childView: self.contentView!, margins: [0,0,0,0]) 170 | 171 | } 172 | 173 | self.setupCube() 174 | 175 | self.isShowing = true 176 | 177 | self.blurView!.hidden = true 178 | 179 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(CGFloat(NSEC_PER_SEC) * 0.01)), dispatch_get_main_queue()) { () -> Void in 180 | 181 | self.captureBackground() 182 | 183 | self.blurView!.hidden = false 184 | 185 | self.hidden = false 186 | 187 | self.contentView!.hidden = false 188 | 189 | self.captureFront() 190 | 191 | self.contentView!.hidden = true 192 | 193 | APNotificationAlertView.hideAnimated(false) 194 | 195 | APNotificationAlertView.updatePopup(self) 196 | 197 | CATransaction.begin(); 198 | 199 | CATransaction.setCompletionBlock({ 200 | 201 | self.contentView!.hidden = false 202 | 203 | self.isOpen = true 204 | 205 | self.isShowing = false 206 | 207 | if (self.hideAfterDelay > 0){ 208 | 209 | let t = Int64(CGFloat(NSEC_PER_SEC) * self.hideAfterDelay + CGFloat(self.animationDuration)) 210 | 211 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, t), dispatch_get_main_queue(), { 212 | 213 | self.isHiding = true 214 | self.hideWithCompletion(nil) 215 | 216 | }) 217 | 218 | } 219 | }) 220 | 221 | CATransaction.setAnimationDuration(self.animationDuration); 222 | 223 | self.transformLayer!.transform = CATransform3DRotate(self.transformLayer!.transform, CGFloat(M_PI_2), 1, 0, 0) 224 | 225 | CATransaction.commit(); 226 | 227 | } 228 | 229 | } 230 | 231 | //Currently showed popup will be hiden 232 | static func hideAnimated(animated:Bool){ 233 | 234 | if (animated){ 235 | 236 | if (popup != nil){ 237 | 238 | if (popup!.isHiding || popup!.isShowing){ 239 | return 240 | } 241 | 242 | popup!.isHiding = true 243 | 244 | popup!.hideWithCompletion(nil) 245 | 246 | } 247 | 248 | }else{ 249 | 250 | if (popup != nil){ 251 | popup!.removeFromSuperview() 252 | } 253 | 254 | } 255 | 256 | } 257 | 258 | func hideWithCompletion(completion: (() -> Void)?){ 259 | 260 | self.captureFront() 261 | 262 | self.contentView!.removeFromSuperview() 263 | 264 | self.hidden = true 265 | 266 | self.blurView!.hidden = true 267 | 268 | self.captureBackground() 269 | 270 | self.blurView!.hidden = false 271 | 272 | self.hidden = false 273 | 274 | CATransaction.begin() 275 | 276 | CATransaction.setCompletionBlock({ () -> Void in 277 | 278 | self.isOpen = false 279 | 280 | self.isHiding = false 281 | 282 | self.removeFromSuperview() 283 | 284 | if (completion != nil){ 285 | completion!() 286 | } 287 | 288 | }) 289 | 290 | CATransaction.setAnimationDuration(self.animationDuration) 291 | 292 | self.transformLayer!.transform = CATransform3DRotate(self.transformLayer!.transform, CGFloat(-M_PI_2), 1, 0, 0); 293 | 294 | CATransaction.commit() 295 | 296 | } 297 | 298 | static func addMarginConstraints(superView:UIView, childView:UIView, margins:[CGFloat]){ 299 | 300 | superView.addConstraints([ 301 | 302 | NSLayoutConstraint( 303 | item: childView, 304 | attribute: .Leading, 305 | relatedBy: .Equal, 306 | toItem: superView, 307 | attribute: .Leading, 308 | multiplier: 1, 309 | constant: margins[0]), 310 | 311 | NSLayoutConstraint( 312 | item: childView, 313 | attribute: .Top, 314 | relatedBy: .Equal, 315 | toItem: superView, 316 | attribute: .Top, 317 | multiplier: 1, 318 | constant: margins[1]), 319 | 320 | NSLayoutConstraint( 321 | item: childView, 322 | attribute: .Trailing, 323 | relatedBy: .Equal, 324 | toItem: superView, 325 | attribute: .Trailing, 326 | multiplier: 1, 327 | constant: margins[2]), 328 | 329 | NSLayoutConstraint( 330 | item: childView, 331 | attribute: .Bottom, 332 | relatedBy: .Equal, 333 | toItem: superView, 334 | attribute: .Bottom, 335 | multiplier: 1, 336 | constant: margins[3]) 337 | 338 | ]) 339 | 340 | } 341 | 342 | 343 | 344 | override func layoutSublayersOfLayer(layer: CALayer) { 345 | 346 | super.layoutSublayersOfLayer(layer) 347 | 348 | self.backgroundImageView.layer.frame = self.bounds 349 | 350 | self.frontImageView.layer.frame = self.bounds 351 | 352 | } 353 | 354 | private func setupCube(){ 355 | 356 | var pt = CATransform3DIdentity; 357 | pt.m34 = -1.0 / 300.0; 358 | self.layer.sublayerTransform = pt; 359 | 360 | let front = self.frontImageView.layer 361 | 362 | let background = self.backgroundImageView.layer 363 | 364 | front.transform = CATransform3DTranslate(front.transform, 0, 0, 0); 365 | 366 | front.transform = CATransform3DRotate(front.transform, CGFloat(-M_PI_2), 1, 0, 0); 367 | 368 | background.transform = CATransform3DTranslate(background.transform, 0, -self.height/2.0, self.height/2.0); 369 | 370 | self.transformLayer!.transform = CATransform3DTranslate(self.layer.transform, 0, self.height/2.0, -self.height/2.0); 371 | 372 | } 373 | 374 | private static func updatePopup(popupView:APNotificationAlertView){ 375 | 376 | popup = popupView; 377 | 378 | } 379 | 380 | private func captureBackground(){ 381 | 382 | let layer = UIApplication.sharedApplication().keyWindow!.layer 383 | 384 | let scale = UIScreen.mainScreen().scale 385 | 386 | UIGraphicsBeginImageContextWithOptions(CGSizeMake(layer.frame.size.width, self.height), false, scale) 387 | 388 | let context = UIGraphicsGetCurrentContext()! 389 | 390 | CGContextConcatCTM(context, CGAffineTransformMakeTranslation(0, -self.frame.origin.y)) 391 | 392 | layer.renderInContext(context) 393 | 394 | self.backgroundImageView.image = UIGraphicsGetImageFromCurrentImageContext() 395 | 396 | UIGraphicsEndImageContext(); 397 | 398 | 399 | } 400 | 401 | private func captureFront(){ 402 | 403 | let layer = UIApplication.sharedApplication().keyWindow!.layer 404 | 405 | let scale = UIScreen.mainScreen().scale 406 | 407 | UIGraphicsBeginImageContextWithOptions(CGSizeMake(layer.frame.size.width, self.height), false, scale) 408 | 409 | let context = UIGraphicsGetCurrentContext()! 410 | 411 | self.contentView!.layer.renderInContext(context); 412 | 413 | self.frontImageView.image = UIGraphicsGetImageFromCurrentImageContext(); 414 | 415 | UIGraphicsEndImageContext(); 416 | 417 | } 418 | 419 | 420 | private func addConstraintsToPopup(){ 421 | 422 | self.heightConstraint = NSLayoutConstraint( 423 | item: self, 424 | attribute: NSLayoutAttribute.Height, 425 | relatedBy: NSLayoutRelation.Equal, 426 | toItem: nil, 427 | attribute: NSLayoutAttribute.NotAnAttribute, 428 | multiplier: 1, 429 | constant: self.height) 430 | 431 | self.addConstraint(self.heightConstraint!) 432 | 433 | self.superview!.addConstraints([ 434 | 435 | NSLayoutConstraint( 436 | item: self, 437 | attribute: .Leading, 438 | relatedBy: .Equal, 439 | toItem: self.superview, 440 | attribute: .Leading, 441 | multiplier: 1, 442 | constant: 0), 443 | 444 | NSLayoutConstraint( 445 | item: self, 446 | attribute: .Trailing, 447 | relatedBy: .Equal, 448 | toItem: self.superview, 449 | attribute: .Trailing, 450 | multiplier: 1, 451 | constant: 0), 452 | 453 | ]) 454 | 455 | self.addTopConstraint() 456 | 457 | } 458 | 459 | private func addTopConstraint(){ 460 | 461 | if (self.positionConstraint != nil){ 462 | self.superview!.removeConstraint(self.positionConstraint!) 463 | } 464 | 465 | self.positionConstraint = NSLayoutConstraint( 466 | item: self, 467 | attribute: .Top, 468 | relatedBy: .Equal, 469 | toItem: self.superview, 470 | attribute: .Top, 471 | multiplier: 1, 472 | constant: 0) 473 | 474 | self.superview!.addConstraint(self.positionConstraint!) 475 | 476 | } 477 | 478 | private func addBottomConstraint(){ 479 | 480 | if (self.positionConstraint != nil){ 481 | self.superview!.removeConstraint(self.positionConstraint!) 482 | } 483 | 484 | self.positionConstraint = NSLayoutConstraint( 485 | item: self, 486 | attribute: .Bottom, 487 | relatedBy: .Equal, 488 | toItem: self.superview, 489 | attribute: .Bottom, 490 | multiplier: 1, 491 | constant: 0) 492 | 493 | self.superview!.addConstraint(self.positionConstraint!) 494 | 495 | } 496 | 497 | private func addBlurConstraints(){ 498 | 499 | superview!.addConstraints([ 500 | 501 | NSLayoutConstraint( 502 | item: self.blurView!, 503 | attribute: .Leading, 504 | relatedBy: .Equal, 505 | toItem: self, 506 | attribute: .Leading, 507 | multiplier: 1, 508 | constant: 0), 509 | 510 | NSLayoutConstraint( 511 | item: self.blurView!, 512 | attribute: .Trailing, 513 | relatedBy: .Equal, 514 | toItem: self, 515 | attribute: .Trailing, 516 | multiplier: 1, 517 | constant: 0), 518 | 519 | NSLayoutConstraint( 520 | item: self.blurView!, 521 | attribute: .Top, 522 | relatedBy: .Equal, 523 | toItem: self, 524 | attribute: .Top, 525 | multiplier: 1, 526 | constant: 0), 527 | 528 | NSLayoutConstraint( 529 | item: self.blurView!, 530 | attribute: .Bottom, 531 | relatedBy: .Equal, 532 | toItem: self, 533 | attribute: .Bottom, 534 | multiplier: 1, 535 | constant: 0) 536 | 537 | ]) 538 | } 539 | 540 | } 541 | -------------------------------------------------------------------------------- /APNotificationAlertView/APNotificationAlertViewBaseExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // APNotificationAlertViewBaseExtension.swift 3 | // AppusNotificationPopupExample 4 | // 5 | // Created by Andrey Pervushin on 27.10.15. 6 | // Copyright © 2015 Andrey Pervushin. All rights reserved. 7 | // 8 | import UIKit 9 | 10 | extension APNotificationAlertView { 11 | 12 | //Simple popup with text. Use hideAfterDelay property or outer action to hide 13 | 14 | static func popupWithText(text:String) -> APNotificationAlertView{ 15 | 16 | //-- Elements 17 | 18 | let view = UIView() 19 | 20 | view.translatesAutoresizingMaskIntoConstraints = false 21 | 22 | view.backgroundColor = UIColor.cyanColor() 23 | 24 | let label = UILabel() 25 | 26 | label.translatesAutoresizingMaskIntoConstraints = false 27 | 28 | label.text = text 29 | 30 | label.textAlignment = NSTextAlignment.Center 31 | 32 | label.numberOfLines = 0 33 | 34 | label.minimumScaleFactor = 0.3 35 | 36 | //-- UI relations 37 | 38 | view.addSubview(label) 39 | 40 | APNotificationAlertView.addMarginConstraints(view, childView: label, margins: [0,0,0,0]) 41 | 42 | return APNotificationAlertView.popupWithView(view) 43 | 44 | } 45 | 46 | //Popup with text and Yes/No options. Use customCompletionHandler to get 47 | //presed option index (Yes:0 No:1) 48 | @available(iOS 9, *) 49 | static func popupWithQuestion(text:String) -> APNotificationAlertView{ 50 | 51 | //-- Elements 52 | 53 | let view = UIView() 54 | 55 | view.translatesAutoresizingMaskIntoConstraints = false 56 | 57 | view.backgroundColor = UIColor(red: 0.9, green: 0.9, blue: 0.95, alpha: 1) 58 | 59 | let icon = UILabel() 60 | 61 | icon.translatesAutoresizingMaskIntoConstraints = false 62 | 63 | icon.text = "?" 64 | 65 | icon.textColor = UIColor.lightGrayColor() 66 | 67 | icon.textAlignment = .Center 68 | 69 | icon.numberOfLines = 0 70 | 71 | icon.layer.cornerRadius = 15 72 | 73 | icon.layer.borderWidth = 1 74 | 75 | icon.layer.borderColor = UIColor.lightGrayColor().CGColor 76 | 77 | 78 | let label = UILabel() 79 | 80 | label.translatesAutoresizingMaskIntoConstraints = false 81 | 82 | label.text = text 83 | 84 | icon.textColor = UIColor.grayColor() 85 | 86 | label.textAlignment = .Center 87 | 88 | label.numberOfLines = 0 89 | 90 | label.minimumScaleFactor = 0.3 91 | 92 | let panel = UIStackView() 93 | 94 | panel.translatesAutoresizingMaskIntoConstraints = false 95 | 96 | panel.axis = .Vertical 97 | 98 | panel.distribution = .FillEqually 99 | 100 | panel.alignment = .Fill 101 | 102 | var buttons = [UIButton]() 103 | 104 | var i = 0; 105 | for title in ["Yes", "No"] { 106 | 107 | let button = UIButton(type: .System) 108 | 109 | button.tag = i 110 | 111 | button.translatesAutoresizingMaskIntoConstraints = false 112 | 113 | button.setTitle(title, forState: .Normal) 114 | 115 | panel.addArrangedSubview(button) 116 | 117 | buttons.append(button) 118 | 119 | i++ 120 | } 121 | 122 | //-- UI relations 123 | 124 | view.addSubview(icon) 125 | 126 | view.addSubview(label) 127 | 128 | view.addSubview(panel) 129 | 130 | APNotificationAlertView.addLeftIconConstraints(view, childView: icon, values: [5,30,30]) 131 | 132 | APNotificationAlertView.addMarginConstraints(view, childView: label, margins: [40,20,-80,0]) 133 | 134 | APNotificationAlertView.addHorizontalSnapConstraints(view, childView: panel, margins: [20,0], layoutAttribute: .Right, width: 80) 135 | 136 | let tempPopup = APNotificationAlertView.popupWithView(view) 137 | 138 | //-- Event Handlers 139 | 140 | for button in buttons{ 141 | button.addTarget(tempPopup, action: "onDialogButtonAction:", forControlEvents: .TouchUpInside) 142 | } 143 | 144 | return tempPopup 145 | } 146 | 147 | 148 | //Popup with text and warious number of options. Use customCompletionHandler 149 | //to get presed option index 150 | @available(iOS 9, *) 151 | static func popupDialogWithText(text:String, options:[String]) -> APNotificationAlertView{ 152 | 153 | //-- Elements 154 | 155 | let view = UIView() 156 | 157 | view.translatesAutoresizingMaskIntoConstraints = false 158 | 159 | view.backgroundColor = UIColor(red: 0.9, green: 0.9, blue: 0.95, alpha: 1) 160 | 161 | let label = UILabel() 162 | 163 | label.translatesAutoresizingMaskIntoConstraints = false 164 | 165 | label.text = text 166 | 167 | label.textAlignment = .Center 168 | 169 | label.numberOfLines = 0 170 | 171 | label.minimumScaleFactor = 0.3 172 | 173 | let panel = UIStackView() 174 | 175 | panel.translatesAutoresizingMaskIntoConstraints = false 176 | 177 | panel.axis = .Horizontal 178 | 179 | panel.distribution = .FillEqually 180 | 181 | panel.alignment = .Fill 182 | 183 | var buttons = [UIButton]() 184 | 185 | var i = 0; 186 | for title in options { 187 | 188 | let button = UIButton(type: .System) 189 | 190 | button.tag = i 191 | 192 | button.translatesAutoresizingMaskIntoConstraints = false 193 | 194 | button.setTitle(title, forState: .Normal) 195 | 196 | panel.addArrangedSubview(button) 197 | 198 | buttons.append(button) 199 | 200 | i++ 201 | } 202 | 203 | //-- UI relations 204 | 205 | view.addSubview(panel) 206 | 207 | view.addSubview(label) 208 | 209 | APNotificationAlertView.addVerticalSnapConstraints(view, childView: panel, layoutAttribute: .Bottom, height: 35) 210 | 211 | APNotificationAlertView.addMarginConstraints(view, childView: label, margins: [50,20,0,-35]) 212 | 213 | 214 | let tempPopup = APNotificationAlertView.popupWithView(view) 215 | 216 | //-- Event Handlers 217 | 218 | for button in buttons{ 219 | button.addTarget(tempPopup, action: "onDialogButtonAction:", forControlEvents: .TouchUpInside) 220 | } 221 | 222 | return tempPopup 223 | 224 | } 225 | 226 | func onDialogButtonAction(button: UIButton){ 227 | 228 | if let completion = self.customCompletionHandler{ 229 | completion(button.tag) 230 | } 231 | 232 | } 233 | 234 | 235 | 236 | static func addLeftIconConstraints(superView:UIView, childView:UIView, values:[CGFloat]){ 237 | 238 | childView.addConstraint(NSLayoutConstraint( 239 | item: childView, 240 | attribute: NSLayoutAttribute.Width, 241 | relatedBy: NSLayoutRelation.Equal, 242 | toItem: nil, 243 | attribute: .NotAnAttribute, 244 | multiplier: 1, 245 | constant: values[1])) 246 | 247 | childView.addConstraint(NSLayoutConstraint( 248 | item: childView, 249 | attribute: NSLayoutAttribute.Height, 250 | relatedBy: NSLayoutRelation.Equal, 251 | toItem: nil, 252 | attribute: .NotAnAttribute, 253 | multiplier: 1, 254 | constant: values[2])) 255 | 256 | superView.addConstraints([ 257 | 258 | NSLayoutConstraint( 259 | item: childView, 260 | attribute: .Leading, 261 | relatedBy: .Equal, 262 | toItem: superView, 263 | attribute: .Leading, 264 | multiplier: 1, 265 | constant: values[0]), 266 | 267 | NSLayoutConstraint( 268 | item: childView, 269 | attribute: .CenterY, 270 | relatedBy: .Equal, 271 | toItem: superView, 272 | attribute: .CenterY, 273 | multiplier: 1, 274 | constant: 0), 275 | 276 | ]) 277 | 278 | } 279 | 280 | 281 | static func addVerticalSnapConstraints(superView:UIView, childView:UIView, layoutAttribute: NSLayoutAttribute, height:CGFloat){ 282 | 283 | childView.addConstraint(NSLayoutConstraint( 284 | item: childView, 285 | attribute: NSLayoutAttribute.Height, 286 | relatedBy: NSLayoutRelation.Equal, 287 | toItem: nil, 288 | attribute: .NotAnAttribute, 289 | multiplier: 1, 290 | constant: height)) 291 | 292 | superView.addConstraints([ 293 | 294 | NSLayoutConstraint( 295 | item: childView, 296 | attribute: .Leading, 297 | relatedBy: .Equal, 298 | toItem: superView, 299 | attribute: .Leading, 300 | multiplier: 1, 301 | constant: 0), 302 | 303 | NSLayoutConstraint( 304 | item: childView, 305 | attribute: .Trailing, 306 | relatedBy: .Equal, 307 | toItem: superView, 308 | attribute: .Trailing, 309 | multiplier: 1, 310 | constant: 0), 311 | 312 | NSLayoutConstraint( 313 | item: childView, 314 | attribute: layoutAttribute, 315 | relatedBy: .Equal, 316 | toItem: superView, 317 | attribute: layoutAttribute, 318 | multiplier: 1, 319 | constant: 0), 320 | 321 | ]) 322 | 323 | } 324 | 325 | static func addMarginSizeConstraints(superView:UIView, childView:UIView, values:[CGFloat]){ 326 | 327 | childView.addConstraint(NSLayoutConstraint( 328 | item: childView, 329 | attribute: NSLayoutAttribute.Width, 330 | relatedBy: NSLayoutRelation.Equal, 331 | toItem: nil, 332 | attribute: .NotAnAttribute, 333 | multiplier: 1, 334 | constant: values[2])) 335 | 336 | childView.addConstraint(NSLayoutConstraint( 337 | item: childView, 338 | attribute: NSLayoutAttribute.Height, 339 | relatedBy: NSLayoutRelation.Equal, 340 | toItem: nil, 341 | attribute: .NotAnAttribute, 342 | multiplier: 1, 343 | constant: values[3])) 344 | 345 | superView.addConstraints([ 346 | 347 | NSLayoutConstraint( 348 | item: childView, 349 | attribute: .Left, 350 | relatedBy: .Equal, 351 | toItem: superView, 352 | attribute: .Left, 353 | multiplier: 1, 354 | constant: values[0]), 355 | NSLayoutConstraint( 356 | item: childView, 357 | attribute: .Top, 358 | relatedBy: .Equal, 359 | toItem: superView, 360 | attribute: .Top, 361 | multiplier: 1, 362 | constant: values[1]), 363 | 364 | ]) 365 | 366 | } 367 | 368 | static func addHorizontalSnapConstraints(superView:UIView, childView:UIView, margins:[CGFloat], layoutAttribute: NSLayoutAttribute, width:CGFloat){ 369 | 370 | childView.addConstraint(NSLayoutConstraint( 371 | item: childView, 372 | attribute: NSLayoutAttribute.Width, 373 | relatedBy: NSLayoutRelation.Equal, 374 | toItem: nil, 375 | attribute: .NotAnAttribute, 376 | multiplier: 1, 377 | constant: width)) 378 | 379 | superView.addConstraints([ 380 | 381 | NSLayoutConstraint( 382 | item: childView, 383 | attribute: .Top, 384 | relatedBy: .Equal, 385 | toItem: superView, 386 | attribute: .Top, 387 | multiplier: 1, 388 | constant: margins[0]), 389 | 390 | NSLayoutConstraint( 391 | item: childView, 392 | attribute: .Bottom, 393 | relatedBy: .Equal, 394 | toItem: superView, 395 | attribute: .Bottom, 396 | multiplier: 1, 397 | constant: margins[1]), 398 | 399 | NSLayoutConstraint( 400 | item: childView, 401 | attribute: layoutAttribute, 402 | relatedBy: .Equal, 403 | toItem: superView, 404 | attribute: layoutAttribute, 405 | multiplier: 1, 406 | constant: 0), 407 | 408 | ]) 409 | 410 | } 411 | 412 | 413 | 414 | } 415 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /NotificationAlertView.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "NotificationAlertView" 3 | s.version = "0.0.3" 4 | s.summary = "APNotificationAlertView allow you to show any view as popup notification with cube transform." 5 | s.homepage = "http://appus.pro" 6 | s.license = { :type => "Apache", :file => 'LICENSE' } 7 | s.author = { "Alexey Kubas" => "alexey.kubas@appus.me" } 8 | s.platform = :ios 9 | s.ios.deployment_target = "8.0" 10 | s.source = { :git => "https://github.com/alexey-kubas-appus/Notification-AlertView.git", :tag => "0.0.3" } 11 | s.source_files = "APNotificationAlertView", "APNotificationAlertView/*.{h,m}" 12 | s.frameworks = 'Foundation', 'UIKit' 13 | s.requires_arc = true 14 | end 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | APNotificationAlertView 2 | ===================== 3 | 4 | Made by [![Appus Studio](Resource/appus.png)](https://appus.software) 5 | 6 | 'APNotificationAlertView' allow you to show any view as popup notification with cube transform. Developed for easy extension and flexible integration.:point_up: 7 | 8 | * [Setup](#setup) 9 | * [Demo usage](#demo-usage) 10 | * [Popup with custom view](#popup-with-custom-view) 11 | * [Question popup](#question-popup) 12 | * [Dialog popup](#dialog-popup) 13 | * [Text popup](#text-popup) 14 | * [Info](#info) 15 | 16 | #Setup 17 | ```Ruby 18 | pod 'NotificationAlertView' 19 | ``` 20 | 21 | # Demo usage 22 | 23 | ##Popup with custom view 24 | 25 | As a popup may be used any view for example view configured from storyboard 26 | ``` 27 | let popup = APNotificationAlertView.popupWithView(self.samplePopupView) 28 | 29 | popup.show() 30 | ``` 31 | change height or popup position 32 | ``` 33 | let popup = APNotificationAlertView.popupWithView(self.samplePopupView) 34 | 35 | popup.position = APNotificationAlertViewPosition.Bottom 36 | 37 | popup.height = 150 38 | 39 | popup.show() 40 | ``` 41 | 42 | ![](Resource/NotificationPopupStoryboardExample.gif) 43 | 44 | ##Question popup 45 | 46 | Popup with text and Yes/No options. Use customCompletionHandler to get presed option index (Yes:0 No:1) 47 | ``` 48 | let question = "Lorem ipsum dolor sit amet?" 49 | 50 | let popup = APNotificationAlertView.popupWithQuestion(question) 51 | 52 | popup.customCompletionHandler = { 53 | 54 | (index: Int) -> Void in 55 | 56 | APNotificationAlertView.hideAnimated(true) 57 | 58 | print("Taped button at index: \(index)") 59 | 60 | } 61 | 62 | popup.show() 63 | ``` 64 | ![](Resource/NotificationPopupQuestionExample.gif) 65 | 66 | ##Dialog popup 67 | 68 | Popup with text and warious number of options. Use customCompletionHandler to get presed option index 69 | ``` 70 | let question = "Lorem ipsum dolor sit amet?" 71 | 72 | let buttonTitles = ["Yes", "No", "Oh No!"] 73 | 74 | let popup = APNotificationAlertView.popupDialogWithText(question, options: buttonTitles) 75 | 76 | popup.customCompletionHandler = { 77 | 78 | (index: Int) -> Void in 79 | 80 | APNotificationAlertView.hideAnimated(true) 81 | 82 | let alert = UIAlertController(title: "Taped button", message: "at index: \(index)", preferredStyle: .Alert) 83 | 84 | alert.addAction(UIAlertAction(title: "Ok", 85 | style: UIAlertActionStyle.Default, 86 | handler: { (action) -> Void in 87 | 88 | alert.dismissViewControllerAnimated(true, completion: nil) 89 | 90 | })) 91 | 92 | self.presentViewController(alert, animated: true, completion: nil) 93 | 94 | } 95 | 96 | popup.animationDuration = 1 97 | 98 | popup.show() 99 | ``` 100 | ![](Resource/NotificationPopupDialogExample.gif) 101 | 102 | 103 | ##Text popup 104 | 105 | Simple popup with text. Use hideAfterDelay property or outer action to hide 106 | 107 | 108 | ``` 109 | let popup = APNotificationAlertView.popupWithText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.") 110 | 111 | popup.hideAfterDelay = 3 112 | 113 | popup.animationDuration = 1 114 | 115 | popup.show() 116 | ``` 117 | 118 | ![](Resource/NotificationPopupTextExample.gif) 119 | 120 | 121 | Developed By 122 | ------------ 123 | 124 | * Alexey Kubas, Andrey Pervushin, [Appus Studio](https://appus.software) 125 | 126 | License 127 | -------- 128 | 129 | Copyright 2015 Appus Studio. 130 | 131 | Licensed under the Apache License, Version 2.0 (the "License"); 132 | you may not use this file except in compliance with the License. 133 | You may obtain a copy of the License at 134 | 135 | http://www.apache.org/licenses/LICENSE-2.0 136 | 137 | Unless required by applicable law or agreed to in writing, software 138 | distributed under the License is distributed on an "AS IS" BASIS, 139 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 140 | See the License for the specific language governing permissions and 141 | limitations under the License. 142 | -------------------------------------------------------------------------------- /Resource/NotificationPopupDialogExample.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appus-studio/Notification-AlertView/9b32629795d3ec3b59a0aec51eccecff4d64faca/Resource/NotificationPopupDialogExample.gif -------------------------------------------------------------------------------- /Resource/NotificationPopupQuestionExample.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appus-studio/Notification-AlertView/9b32629795d3ec3b59a0aec51eccecff4d64faca/Resource/NotificationPopupQuestionExample.gif -------------------------------------------------------------------------------- /Resource/NotificationPopupStoryboardExample.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appus-studio/Notification-AlertView/9b32629795d3ec3b59a0aec51eccecff4d64faca/Resource/NotificationPopupStoryboardExample.gif -------------------------------------------------------------------------------- /Resource/NotificationPopupTextExample.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appus-studio/Notification-AlertView/9b32629795d3ec3b59a0aec51eccecff4d64faca/Resource/NotificationPopupTextExample.gif -------------------------------------------------------------------------------- /Resource/appus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appus-studio/Notification-AlertView/9b32629795d3ec3b59a0aec51eccecff4d64faca/Resource/appus.png -------------------------------------------------------------------------------- /demo/AppusNotificationPopupExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D733A2021BDFC7A400149C47 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D733A2011BDFC7A400149C47 /* AppDelegate.swift */; }; 11 | D733A2041BDFC7A400149C47 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D733A2031BDFC7A400149C47 /* ViewController.swift */; }; 12 | D733A2071BDFC7A400149C47 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D733A2051BDFC7A400149C47 /* Main.storyboard */; }; 13 | D733A2091BDFC7A400149C47 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D733A2081BDFC7A400149C47 /* Assets.xcassets */; }; 14 | D733A20C1BDFC7A400149C47 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D733A20A1BDFC7A400149C47 /* LaunchScreen.storyboard */; }; 15 | D745F6221BE2210B000A9145 /* LabelCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D745F6211BE2210B000A9145 /* LabelCollectionViewCell.swift */; }; 16 | D75807F71C57743100090CFE /* APNotificationAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D75807F51C57743100090CFE /* APNotificationAlertView.swift */; }; 17 | D75807F81C57743100090CFE /* APNotificationAlertViewBaseExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D75807F61C57743100090CFE /* APNotificationAlertViewBaseExtension.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | D733A1FE1BDFC7A400149C47 /* AppusNotificationPopupExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AppusNotificationPopupExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | D733A2011BDFC7A400149C47 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | D733A2031BDFC7A400149C47 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | D733A2061BDFC7A400149C47 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | D733A2081BDFC7A400149C47 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | D733A20B1BDFC7A400149C47 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | D733A20D1BDFC7A400149C47 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | D745F6211BE2210B000A9145 /* LabelCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LabelCollectionViewCell.swift; sourceTree = ""; }; 29 | D75807F51C57743100090CFE /* APNotificationAlertView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = APNotificationAlertView.swift; sourceTree = ""; }; 30 | D75807F61C57743100090CFE /* APNotificationAlertViewBaseExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = APNotificationAlertViewBaseExtension.swift; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | D733A1FB1BDFC7A400149C47 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | D733A1F51BDFC7A400149C47 = { 45 | isa = PBXGroup; 46 | children = ( 47 | D733A2001BDFC7A400149C47 /* NotificationPopupExample */, 48 | D733A1FF1BDFC7A400149C47 /* Products */, 49 | ); 50 | sourceTree = ""; 51 | }; 52 | D733A1FF1BDFC7A400149C47 /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | D733A1FE1BDFC7A400149C47 /* AppusNotificationPopupExample.app */, 56 | ); 57 | name = Products; 58 | sourceTree = ""; 59 | }; 60 | D733A2001BDFC7A400149C47 /* NotificationPopupExample */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | D75807F41C57743100090CFE /* APNotificationAlertView */, 64 | D733A2011BDFC7A400149C47 /* AppDelegate.swift */, 65 | D733A2031BDFC7A400149C47 /* ViewController.swift */, 66 | D733A2051BDFC7A400149C47 /* Main.storyboard */, 67 | D745F6211BE2210B000A9145 /* LabelCollectionViewCell.swift */, 68 | D733A2081BDFC7A400149C47 /* Assets.xcassets */, 69 | D733A20A1BDFC7A400149C47 /* LaunchScreen.storyboard */, 70 | D733A20D1BDFC7A400149C47 /* Info.plist */, 71 | ); 72 | path = NotificationPopupExample; 73 | sourceTree = ""; 74 | }; 75 | D75807F41C57743100090CFE /* APNotificationAlertView */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | D75807F51C57743100090CFE /* APNotificationAlertView.swift */, 79 | D75807F61C57743100090CFE /* APNotificationAlertViewBaseExtension.swift */, 80 | ); 81 | path = APNotificationAlertView; 82 | sourceTree = ""; 83 | }; 84 | /* End PBXGroup section */ 85 | 86 | /* Begin PBXNativeTarget section */ 87 | D733A1FD1BDFC7A400149C47 /* AppusNotificationPopupExample */ = { 88 | isa = PBXNativeTarget; 89 | buildConfigurationList = D733A2101BDFC7A400149C47 /* Build configuration list for PBXNativeTarget "AppusNotificationPopupExample" */; 90 | buildPhases = ( 91 | D733A1FA1BDFC7A400149C47 /* Sources */, 92 | D733A1FB1BDFC7A400149C47 /* Frameworks */, 93 | D733A1FC1BDFC7A400149C47 /* Resources */, 94 | ); 95 | buildRules = ( 96 | ); 97 | dependencies = ( 98 | ); 99 | name = AppusNotificationPopupExample; 100 | productName = NotificationPopupExample; 101 | productReference = D733A1FE1BDFC7A400149C47 /* AppusNotificationPopupExample.app */; 102 | productType = "com.apple.product-type.application"; 103 | }; 104 | /* End PBXNativeTarget section */ 105 | 106 | /* Begin PBXProject section */ 107 | D733A1F61BDFC7A400149C47 /* Project object */ = { 108 | isa = PBXProject; 109 | attributes = { 110 | LastSwiftUpdateCheck = 0710; 111 | LastUpgradeCheck = 0710; 112 | ORGANIZATIONNAME = "Andrey Pervushin"; 113 | TargetAttributes = { 114 | D733A1FD1BDFC7A400149C47 = { 115 | CreatedOnToolsVersion = 7.1; 116 | }; 117 | }; 118 | }; 119 | buildConfigurationList = D733A1F91BDFC7A400149C47 /* Build configuration list for PBXProject "AppusNotificationPopupExample" */; 120 | compatibilityVersion = "Xcode 3.2"; 121 | developmentRegion = English; 122 | hasScannedForEncodings = 0; 123 | knownRegions = ( 124 | en, 125 | Base, 126 | ); 127 | mainGroup = D733A1F51BDFC7A400149C47; 128 | productRefGroup = D733A1FF1BDFC7A400149C47 /* Products */; 129 | projectDirPath = ""; 130 | projectRoot = ""; 131 | targets = ( 132 | D733A1FD1BDFC7A400149C47 /* AppusNotificationPopupExample */, 133 | ); 134 | }; 135 | /* End PBXProject section */ 136 | 137 | /* Begin PBXResourcesBuildPhase section */ 138 | D733A1FC1BDFC7A400149C47 /* Resources */ = { 139 | isa = PBXResourcesBuildPhase; 140 | buildActionMask = 2147483647; 141 | files = ( 142 | D733A20C1BDFC7A400149C47 /* LaunchScreen.storyboard in Resources */, 143 | D733A2091BDFC7A400149C47 /* Assets.xcassets in Resources */, 144 | D733A2071BDFC7A400149C47 /* Main.storyboard in Resources */, 145 | ); 146 | runOnlyForDeploymentPostprocessing = 0; 147 | }; 148 | /* End PBXResourcesBuildPhase section */ 149 | 150 | /* Begin PBXSourcesBuildPhase section */ 151 | D733A1FA1BDFC7A400149C47 /* Sources */ = { 152 | isa = PBXSourcesBuildPhase; 153 | buildActionMask = 2147483647; 154 | files = ( 155 | D733A2041BDFC7A400149C47 /* ViewController.swift in Sources */, 156 | D745F6221BE2210B000A9145 /* LabelCollectionViewCell.swift in Sources */, 157 | D733A2021BDFC7A400149C47 /* AppDelegate.swift in Sources */, 158 | D75807F81C57743100090CFE /* APNotificationAlertViewBaseExtension.swift in Sources */, 159 | D75807F71C57743100090CFE /* APNotificationAlertView.swift in Sources */, 160 | ); 161 | runOnlyForDeploymentPostprocessing = 0; 162 | }; 163 | /* End PBXSourcesBuildPhase section */ 164 | 165 | /* Begin PBXVariantGroup section */ 166 | D733A2051BDFC7A400149C47 /* Main.storyboard */ = { 167 | isa = PBXVariantGroup; 168 | children = ( 169 | D733A2061BDFC7A400149C47 /* Base */, 170 | ); 171 | name = Main.storyboard; 172 | sourceTree = ""; 173 | }; 174 | D733A20A1BDFC7A400149C47 /* LaunchScreen.storyboard */ = { 175 | isa = PBXVariantGroup; 176 | children = ( 177 | D733A20B1BDFC7A400149C47 /* Base */, 178 | ); 179 | name = LaunchScreen.storyboard; 180 | sourceTree = ""; 181 | }; 182 | /* End PBXVariantGroup section */ 183 | 184 | /* Begin XCBuildConfiguration section */ 185 | D733A20E1BDFC7A400149C47 /* Debug */ = { 186 | isa = XCBuildConfiguration; 187 | buildSettings = { 188 | ALWAYS_SEARCH_USER_PATHS = NO; 189 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 190 | CLANG_CXX_LIBRARY = "libc++"; 191 | CLANG_ENABLE_MODULES = YES; 192 | CLANG_ENABLE_OBJC_ARC = YES; 193 | CLANG_WARN_BOOL_CONVERSION = YES; 194 | CLANG_WARN_CONSTANT_CONVERSION = YES; 195 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 196 | CLANG_WARN_EMPTY_BODY = YES; 197 | CLANG_WARN_ENUM_CONVERSION = YES; 198 | CLANG_WARN_INT_CONVERSION = YES; 199 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 200 | CLANG_WARN_UNREACHABLE_CODE = YES; 201 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 202 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 203 | COPY_PHASE_STRIP = NO; 204 | DEBUG_INFORMATION_FORMAT = dwarf; 205 | ENABLE_STRICT_OBJC_MSGSEND = YES; 206 | ENABLE_TESTABILITY = YES; 207 | GCC_C_LANGUAGE_STANDARD = gnu99; 208 | GCC_DYNAMIC_NO_PIC = NO; 209 | GCC_NO_COMMON_BLOCKS = YES; 210 | GCC_OPTIMIZATION_LEVEL = 0; 211 | GCC_PREPROCESSOR_DEFINITIONS = ( 212 | "DEBUG=1", 213 | "$(inherited)", 214 | ); 215 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 216 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 217 | GCC_WARN_UNDECLARED_SELECTOR = YES; 218 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 219 | GCC_WARN_UNUSED_FUNCTION = YES; 220 | GCC_WARN_UNUSED_VARIABLE = YES; 221 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 222 | MTL_ENABLE_DEBUG_INFO = YES; 223 | ONLY_ACTIVE_ARCH = YES; 224 | SDKROOT = iphoneos; 225 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 226 | TARGETED_DEVICE_FAMILY = "1,2"; 227 | }; 228 | name = Debug; 229 | }; 230 | D733A20F1BDFC7A400149C47 /* Release */ = { 231 | isa = XCBuildConfiguration; 232 | buildSettings = { 233 | ALWAYS_SEARCH_USER_PATHS = NO; 234 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 235 | CLANG_CXX_LIBRARY = "libc++"; 236 | CLANG_ENABLE_MODULES = YES; 237 | CLANG_ENABLE_OBJC_ARC = YES; 238 | CLANG_WARN_BOOL_CONVERSION = YES; 239 | CLANG_WARN_CONSTANT_CONVERSION = YES; 240 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 241 | CLANG_WARN_EMPTY_BODY = YES; 242 | CLANG_WARN_ENUM_CONVERSION = YES; 243 | CLANG_WARN_INT_CONVERSION = YES; 244 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 245 | CLANG_WARN_UNREACHABLE_CODE = YES; 246 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 247 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 248 | COPY_PHASE_STRIP = NO; 249 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 250 | ENABLE_NS_ASSERTIONS = NO; 251 | ENABLE_STRICT_OBJC_MSGSEND = YES; 252 | GCC_C_LANGUAGE_STANDARD = gnu99; 253 | GCC_NO_COMMON_BLOCKS = YES; 254 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 255 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 256 | GCC_WARN_UNDECLARED_SELECTOR = YES; 257 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 258 | GCC_WARN_UNUSED_FUNCTION = YES; 259 | GCC_WARN_UNUSED_VARIABLE = YES; 260 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 261 | MTL_ENABLE_DEBUG_INFO = NO; 262 | SDKROOT = iphoneos; 263 | TARGETED_DEVICE_FAMILY = "1,2"; 264 | VALIDATE_PRODUCT = YES; 265 | }; 266 | name = Release; 267 | }; 268 | D733A2111BDFC7A400149C47 /* Debug */ = { 269 | isa = XCBuildConfiguration; 270 | buildSettings = { 271 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 272 | INFOPLIST_FILE = NotificationPopupExample/Info.plist; 273 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 274 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 275 | PRODUCT_BUNDLE_IDENTIFIER = com.appus.NotificationPopupExample; 276 | PRODUCT_NAME = AppusNotificationPopupExample; 277 | }; 278 | name = Debug; 279 | }; 280 | D733A2121BDFC7A400149C47 /* Release */ = { 281 | isa = XCBuildConfiguration; 282 | buildSettings = { 283 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 284 | INFOPLIST_FILE = NotificationPopupExample/Info.plist; 285 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 286 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 287 | PRODUCT_BUNDLE_IDENTIFIER = com.appus.NotificationPopupExample; 288 | PRODUCT_NAME = AppusNotificationPopupExample; 289 | }; 290 | name = Release; 291 | }; 292 | /* End XCBuildConfiguration section */ 293 | 294 | /* Begin XCConfigurationList section */ 295 | D733A1F91BDFC7A400149C47 /* Build configuration list for PBXProject "AppusNotificationPopupExample" */ = { 296 | isa = XCConfigurationList; 297 | buildConfigurations = ( 298 | D733A20E1BDFC7A400149C47 /* Debug */, 299 | D733A20F1BDFC7A400149C47 /* Release */, 300 | ); 301 | defaultConfigurationIsVisible = 0; 302 | defaultConfigurationName = Release; 303 | }; 304 | D733A2101BDFC7A400149C47 /* Build configuration list for PBXNativeTarget "AppusNotificationPopupExample" */ = { 305 | isa = XCConfigurationList; 306 | buildConfigurations = ( 307 | D733A2111BDFC7A400149C47 /* Debug */, 308 | D733A2121BDFC7A400149C47 /* Release */, 309 | ); 310 | defaultConfigurationIsVisible = 0; 311 | defaultConfigurationName = Release; 312 | }; 313 | /* End XCConfigurationList section */ 314 | }; 315 | rootObject = D733A1F61BDFC7A400149C47 /* Project object */; 316 | } 317 | -------------------------------------------------------------------------------- /demo/AppusNotificationPopupExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /demo/NotificationPopupExample/APNotificationAlertView/APNotificationAlertView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // APNotificationAlertView.swift 3 | // AppusNotificationPopupExample 4 | // 5 | // Created by Andrey Pervushin on 16.10.15. 6 | // Copyright © 2015 Andrey Pervushin. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | enum APNotificationAlertViewPosition: Int { 12 | 13 | case Top, Bottom, Custom 14 | 15 | } 16 | 17 | class APNotificationAlertView: UIView { 18 | 19 | 20 | static var popup:APNotificationAlertView? 21 | 22 | //May be used in custom popup extensions if you should send some response 23 | //based on some actions 24 | var customCompletionHandler:((Int) -> Void)? 25 | 26 | //Show/hide animation duration in seconds 27 | var animationDuration: CFTimeInterval = 0.5 28 | 29 | //If this value not equal to "0" popup will hide after specified time in 30 | //seconds 31 | var hideAfterDelay: CGFloat = 0 32 | 33 | //View that is showing in popup, you may use it to get any properties from 34 | //your view. (Change it it on your own risk) 35 | var contentView: UIView? 36 | 37 | //Chage this to show popup from top or bottom 38 | var position: APNotificationAlertViewPosition!{ 39 | didSet{ 40 | 41 | switch position! { 42 | case .Top: 43 | self.addTopConstraint() 44 | return 45 | 46 | case .Bottom: 47 | self.addBottomConstraint() 48 | return 49 | 50 | default: 51 | return 52 | } 53 | } 54 | } 55 | 56 | 57 | //Set the value that will be best for your project 58 | var height : CGFloat = 100 { 59 | 60 | didSet{ 61 | 62 | if (self.heightConstraint != nil){ 63 | 64 | self.heightConstraint!.constant = height 65 | 66 | } 67 | } 68 | } 69 | 70 | private var blurView: UIVisualEffectView? 71 | 72 | private var backgroundImageView = UIImageView.init() 73 | 74 | private var frontImageView = UIImageView.init() 75 | 76 | private var heightConstraint:NSLayoutConstraint? 77 | 78 | private var positionConstraint:NSLayoutConstraint? 79 | 80 | private var isOpen = false 81 | 82 | private var isShowing = false 83 | 84 | private var isHiding = false 85 | 86 | private var transformLayer: CATransformLayer? 87 | 88 | 89 | //Construct popup with any specified view. View will fit popup size however 90 | //be carefull with constraints specified in it 91 | static func popupWithView(view:UIView?) -> APNotificationAlertView{ 92 | 93 | //-- Elements 94 | 95 | let tempPopup = APNotificationAlertView() 96 | 97 | tempPopup.contentView = view 98 | 99 | for c in tempPopup.contentView!.constraints { 100 | 101 | if ( c.firstAttribute == .Height || c.firstAttribute == .Width){ 102 | 103 | tempPopup.contentView!.removeConstraint(c) 104 | 105 | } 106 | 107 | } 108 | 109 | tempPopup.hidden = true 110 | 111 | tempPopup.translatesAutoresizingMaskIntoConstraints = false 112 | 113 | tempPopup.backgroundImageView.translatesAutoresizingMaskIntoConstraints = false 114 | 115 | tempPopup.frontImageView.translatesAutoresizingMaskIntoConstraints = false 116 | 117 | tempPopup.transformLayer = CATransformLayer(); 118 | 119 | //-- Blur View 120 | 121 | tempPopup.backgroundColor = UIColor.clearColor() 122 | 123 | let blur = UIBlurEffect(style: UIBlurEffectStyle.Light) 124 | 125 | tempPopup.blurView = UIVisualEffectView(effect: blur) 126 | 127 | tempPopup.blurView!.translatesAutoresizingMaskIntoConstraints = false 128 | 129 | //-- UI relations 130 | 131 | let root = UIApplication.sharedApplication().keyWindow! 132 | 133 | root.addSubview(tempPopup) 134 | 135 | tempPopup.addConstraintsToPopup() 136 | 137 | tempPopup.layer.addSublayer(tempPopup.transformLayer!) 138 | 139 | tempPopup.transformLayer!.addSublayer(tempPopup.backgroundImageView.layer) 140 | 141 | tempPopup.transformLayer!.addSublayer(tempPopup.frontImageView.layer) 142 | 143 | //-- Blur View 144 | 145 | tempPopup.superview!.addSubview(tempPopup.blurView!) 146 | 147 | tempPopup.superview!.insertSubview(tempPopup.blurView!, belowSubview: tempPopup) 148 | 149 | tempPopup.addBlurConstraints() 150 | 151 | return tempPopup 152 | 153 | } 154 | 155 | 156 | 157 | //Use it to show popup once it was constructed and hide previous 158 | func show(){ 159 | 160 | 161 | if (self.contentView != nil){ 162 | 163 | self.contentView!.removeFromSuperview() 164 | 165 | self.contentView!.translatesAutoresizingMaskIntoConstraints = false 166 | 167 | self.addSubview(self.contentView!) 168 | 169 | APNotificationAlertView.addMarginConstraints(self, childView: self.contentView!, margins: [0,0,0,0]) 170 | 171 | } 172 | 173 | self.setupCube() 174 | 175 | self.isShowing = true 176 | 177 | self.blurView!.hidden = true 178 | 179 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(CGFloat(NSEC_PER_SEC) * 0.01)), dispatch_get_main_queue()) { () -> Void in 180 | 181 | self.captureBackground() 182 | 183 | self.blurView!.hidden = false 184 | 185 | self.hidden = false 186 | 187 | self.contentView!.hidden = false 188 | 189 | self.captureFront() 190 | 191 | self.contentView!.hidden = true 192 | 193 | APNotificationAlertView.hideAnimated(false) 194 | 195 | APNotificationAlertView.updatePopup(self) 196 | 197 | CATransaction.begin(); 198 | 199 | CATransaction.setCompletionBlock({ 200 | 201 | self.contentView!.hidden = false 202 | 203 | self.isOpen = true 204 | 205 | self.isShowing = false 206 | 207 | if (self.hideAfterDelay > 0){ 208 | 209 | let t = Int64(CGFloat(NSEC_PER_SEC) * self.hideAfterDelay + CGFloat(self.animationDuration)) 210 | 211 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, t), dispatch_get_main_queue(), { 212 | 213 | self.isHiding = true 214 | self.hideWithCompletion(nil) 215 | 216 | }) 217 | 218 | } 219 | }) 220 | 221 | CATransaction.setAnimationDuration(self.animationDuration); 222 | 223 | self.transformLayer!.transform = CATransform3DRotate(self.transformLayer!.transform, CGFloat(M_PI_2), 1, 0, 0) 224 | 225 | CATransaction.commit(); 226 | 227 | } 228 | 229 | } 230 | 231 | //Currently showed popup will be hiden 232 | static func hideAnimated(animated:Bool){ 233 | 234 | if (animated){ 235 | 236 | if (popup != nil){ 237 | 238 | if (popup!.isHiding || popup!.isShowing){ 239 | return 240 | } 241 | 242 | popup!.isHiding = true 243 | 244 | popup!.hideWithCompletion(nil) 245 | 246 | } 247 | 248 | }else{ 249 | 250 | if (popup != nil){ 251 | popup!.removeFromSuperview() 252 | } 253 | 254 | } 255 | 256 | } 257 | 258 | func hideWithCompletion(completion: (() -> Void)?){ 259 | 260 | self.captureFront() 261 | 262 | self.contentView!.removeFromSuperview() 263 | 264 | self.hidden = true 265 | 266 | self.blurView!.hidden = true 267 | 268 | self.captureBackground() 269 | 270 | self.blurView!.hidden = false 271 | 272 | self.hidden = false 273 | 274 | CATransaction.begin() 275 | 276 | CATransaction.setCompletionBlock({ () -> Void in 277 | 278 | self.isOpen = false 279 | 280 | self.isHiding = false 281 | 282 | self.removeFromSuperview() 283 | 284 | if (completion != nil){ 285 | completion!() 286 | } 287 | 288 | }) 289 | 290 | CATransaction.setAnimationDuration(self.animationDuration) 291 | 292 | self.transformLayer!.transform = CATransform3DRotate(self.transformLayer!.transform, CGFloat(-M_PI_2), 1, 0, 0); 293 | 294 | CATransaction.commit() 295 | 296 | } 297 | 298 | static func addMarginConstraints(superView:UIView, childView:UIView, margins:[CGFloat]){ 299 | 300 | superView.addConstraints([ 301 | 302 | NSLayoutConstraint( 303 | item: childView, 304 | attribute: .Leading, 305 | relatedBy: .Equal, 306 | toItem: superView, 307 | attribute: .Leading, 308 | multiplier: 1, 309 | constant: margins[0]), 310 | 311 | NSLayoutConstraint( 312 | item: childView, 313 | attribute: .Top, 314 | relatedBy: .Equal, 315 | toItem: superView, 316 | attribute: .Top, 317 | multiplier: 1, 318 | constant: margins[1]), 319 | 320 | NSLayoutConstraint( 321 | item: childView, 322 | attribute: .Trailing, 323 | relatedBy: .Equal, 324 | toItem: superView, 325 | attribute: .Trailing, 326 | multiplier: 1, 327 | constant: margins[2]), 328 | 329 | NSLayoutConstraint( 330 | item: childView, 331 | attribute: .Bottom, 332 | relatedBy: .Equal, 333 | toItem: superView, 334 | attribute: .Bottom, 335 | multiplier: 1, 336 | constant: margins[3]) 337 | 338 | ]) 339 | 340 | } 341 | 342 | 343 | 344 | override func layoutSublayersOfLayer(layer: CALayer) { 345 | 346 | super.layoutSublayersOfLayer(layer) 347 | 348 | self.backgroundImageView.layer.frame = self.bounds 349 | 350 | self.frontImageView.layer.frame = self.bounds 351 | 352 | } 353 | 354 | private func setupCube(){ 355 | 356 | var pt = CATransform3DIdentity; 357 | pt.m34 = -1.0 / 300.0; 358 | self.layer.sublayerTransform = pt; 359 | 360 | let front = self.frontImageView.layer 361 | 362 | let background = self.backgroundImageView.layer 363 | 364 | front.transform = CATransform3DTranslate(front.transform, 0, 0, 0); 365 | 366 | front.transform = CATransform3DRotate(front.transform, CGFloat(-M_PI_2), 1, 0, 0); 367 | 368 | background.transform = CATransform3DTranslate(background.transform, 0, -self.height/2.0, self.height/2.0); 369 | 370 | self.transformLayer!.transform = CATransform3DTranslate(self.layer.transform, 0, self.height/2.0, -self.height/2.0); 371 | 372 | } 373 | 374 | private static func updatePopup(popupView:APNotificationAlertView){ 375 | 376 | popup = popupView; 377 | 378 | } 379 | 380 | private func captureBackground(){ 381 | 382 | let layer = UIApplication.sharedApplication().keyWindow!.layer 383 | 384 | let scale = UIScreen.mainScreen().scale 385 | 386 | UIGraphicsBeginImageContextWithOptions(CGSizeMake(layer.frame.size.width, self.height), false, scale) 387 | 388 | let context = UIGraphicsGetCurrentContext()! 389 | 390 | CGContextConcatCTM(context, CGAffineTransformMakeTranslation(0, -self.frame.origin.y)) 391 | 392 | layer.renderInContext(context) 393 | 394 | self.backgroundImageView.image = UIGraphicsGetImageFromCurrentImageContext() 395 | 396 | UIGraphicsEndImageContext(); 397 | 398 | 399 | } 400 | 401 | private func captureFront(){ 402 | 403 | let layer = UIApplication.sharedApplication().keyWindow!.layer 404 | 405 | let scale = UIScreen.mainScreen().scale 406 | 407 | UIGraphicsBeginImageContextWithOptions(CGSizeMake(layer.frame.size.width, self.height), false, scale) 408 | 409 | let context = UIGraphicsGetCurrentContext()! 410 | 411 | self.contentView!.layer.renderInContext(context); 412 | 413 | self.frontImageView.image = UIGraphicsGetImageFromCurrentImageContext(); 414 | 415 | UIGraphicsEndImageContext(); 416 | 417 | } 418 | 419 | 420 | private func addConstraintsToPopup(){ 421 | 422 | self.heightConstraint = NSLayoutConstraint( 423 | item: self, 424 | attribute: NSLayoutAttribute.Height, 425 | relatedBy: NSLayoutRelation.Equal, 426 | toItem: nil, 427 | attribute: NSLayoutAttribute.NotAnAttribute, 428 | multiplier: 1, 429 | constant: self.height) 430 | 431 | self.addConstraint(self.heightConstraint!) 432 | 433 | self.superview!.addConstraints([ 434 | 435 | NSLayoutConstraint( 436 | item: self, 437 | attribute: .Leading, 438 | relatedBy: .Equal, 439 | toItem: self.superview, 440 | attribute: .Leading, 441 | multiplier: 1, 442 | constant: 0), 443 | 444 | NSLayoutConstraint( 445 | item: self, 446 | attribute: .Trailing, 447 | relatedBy: .Equal, 448 | toItem: self.superview, 449 | attribute: .Trailing, 450 | multiplier: 1, 451 | constant: 0), 452 | 453 | ]) 454 | 455 | self.addTopConstraint() 456 | 457 | } 458 | 459 | private func addTopConstraint(){ 460 | 461 | if (self.positionConstraint != nil){ 462 | self.superview!.removeConstraint(self.positionConstraint!) 463 | } 464 | 465 | self.positionConstraint = NSLayoutConstraint( 466 | item: self, 467 | attribute: .Top, 468 | relatedBy: .Equal, 469 | toItem: self.superview, 470 | attribute: .Top, 471 | multiplier: 1, 472 | constant: 0) 473 | 474 | self.superview!.addConstraint(self.positionConstraint!) 475 | 476 | } 477 | 478 | private func addBottomConstraint(){ 479 | 480 | if (self.positionConstraint != nil){ 481 | self.superview!.removeConstraint(self.positionConstraint!) 482 | } 483 | 484 | self.positionConstraint = NSLayoutConstraint( 485 | item: self, 486 | attribute: .Bottom, 487 | relatedBy: .Equal, 488 | toItem: self.superview, 489 | attribute: .Bottom, 490 | multiplier: 1, 491 | constant: 0) 492 | 493 | self.superview!.addConstraint(self.positionConstraint!) 494 | 495 | } 496 | 497 | private func addBlurConstraints(){ 498 | 499 | superview!.addConstraints([ 500 | 501 | NSLayoutConstraint( 502 | item: self.blurView!, 503 | attribute: .Leading, 504 | relatedBy: .Equal, 505 | toItem: self, 506 | attribute: .Leading, 507 | multiplier: 1, 508 | constant: 0), 509 | 510 | NSLayoutConstraint( 511 | item: self.blurView!, 512 | attribute: .Trailing, 513 | relatedBy: .Equal, 514 | toItem: self, 515 | attribute: .Trailing, 516 | multiplier: 1, 517 | constant: 0), 518 | 519 | NSLayoutConstraint( 520 | item: self.blurView!, 521 | attribute: .Top, 522 | relatedBy: .Equal, 523 | toItem: self, 524 | attribute: .Top, 525 | multiplier: 1, 526 | constant: 0), 527 | 528 | NSLayoutConstraint( 529 | item: self.blurView!, 530 | attribute: .Bottom, 531 | relatedBy: .Equal, 532 | toItem: self, 533 | attribute: .Bottom, 534 | multiplier: 1, 535 | constant: 0) 536 | 537 | ]) 538 | } 539 | 540 | } 541 | -------------------------------------------------------------------------------- /demo/NotificationPopupExample/APNotificationAlertView/APNotificationAlertViewBaseExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // APNotificationAlertViewBaseExtension.swift 3 | // AppusNotificationPopupExample 4 | // 5 | // Created by Andrey Pervushin on 27.10.15. 6 | // Copyright © 2015 Andrey Pervushin. All rights reserved. 7 | // 8 | import UIKit 9 | 10 | extension APNotificationAlertView { 11 | 12 | //Simple popup with text. Use hideAfterDelay property or outer action to hide 13 | 14 | static func popupWithText(text:String) -> APNotificationAlertView{ 15 | 16 | //-- Elements 17 | 18 | let view = UIView() 19 | 20 | view.translatesAutoresizingMaskIntoConstraints = false 21 | 22 | view.backgroundColor = UIColor.cyanColor() 23 | 24 | let label = UILabel() 25 | 26 | label.translatesAutoresizingMaskIntoConstraints = false 27 | 28 | label.text = text 29 | 30 | label.textAlignment = NSTextAlignment.Center 31 | 32 | label.numberOfLines = 0 33 | 34 | label.minimumScaleFactor = 0.3 35 | 36 | //-- UI relations 37 | 38 | view.addSubview(label) 39 | 40 | APNotificationAlertView.addMarginConstraints(view, childView: label, margins: [0,0,0,0]) 41 | 42 | return APNotificationAlertView.popupWithView(view) 43 | 44 | } 45 | 46 | //Popup with text and Yes/No options. Use customCompletionHandler to get 47 | //presed option index (Yes:0 No:1) 48 | @available(iOS 9, *) 49 | static func popupWithQuestion(text:String) -> APNotificationAlertView{ 50 | 51 | //-- Elements 52 | 53 | let view = UIView() 54 | 55 | view.translatesAutoresizingMaskIntoConstraints = false 56 | 57 | view.backgroundColor = UIColor(red: 0.9, green: 0.9, blue: 0.95, alpha: 1) 58 | 59 | let icon = UILabel() 60 | 61 | icon.translatesAutoresizingMaskIntoConstraints = false 62 | 63 | icon.text = "?" 64 | 65 | icon.textColor = UIColor.lightGrayColor() 66 | 67 | icon.textAlignment = .Center 68 | 69 | icon.numberOfLines = 0 70 | 71 | icon.layer.cornerRadius = 15 72 | 73 | icon.layer.borderWidth = 1 74 | 75 | icon.layer.borderColor = UIColor.lightGrayColor().CGColor 76 | 77 | 78 | let label = UILabel() 79 | 80 | label.translatesAutoresizingMaskIntoConstraints = false 81 | 82 | label.text = text 83 | 84 | icon.textColor = UIColor.grayColor() 85 | 86 | label.textAlignment = .Center 87 | 88 | label.numberOfLines = 0 89 | 90 | label.minimumScaleFactor = 0.3 91 | 92 | let panel = UIStackView() 93 | 94 | panel.translatesAutoresizingMaskIntoConstraints = false 95 | 96 | panel.axis = .Vertical 97 | 98 | panel.distribution = .FillEqually 99 | 100 | panel.alignment = .Fill 101 | 102 | var buttons = [UIButton]() 103 | 104 | var i = 0; 105 | for title in ["Yes", "No"] { 106 | 107 | let button = UIButton(type: .System) 108 | 109 | button.tag = i 110 | 111 | button.translatesAutoresizingMaskIntoConstraints = false 112 | 113 | button.setTitle(title, forState: .Normal) 114 | 115 | panel.addArrangedSubview(button) 116 | 117 | buttons.append(button) 118 | 119 | i++ 120 | } 121 | 122 | //-- UI relations 123 | 124 | view.addSubview(icon) 125 | 126 | view.addSubview(label) 127 | 128 | view.addSubview(panel) 129 | 130 | APNotificationAlertView.addLeftIconConstraints(view, childView: icon, values: [5,30,30]) 131 | 132 | APNotificationAlertView.addMarginConstraints(view, childView: label, margins: [40,20,-80,0]) 133 | 134 | APNotificationAlertView.addHorizontalSnapConstraints(view, childView: panel, margins: [20,0], layoutAttribute: .Right, width: 80) 135 | 136 | let tempPopup = APNotificationAlertView.popupWithView(view) 137 | 138 | //-- Event Handlers 139 | 140 | for button in buttons{ 141 | button.addTarget(tempPopup, action: "onDialogButtonAction:", forControlEvents: .TouchUpInside) 142 | } 143 | 144 | return tempPopup 145 | } 146 | 147 | 148 | //Popup with text and warious number of options. Use customCompletionHandler 149 | //to get presed option index 150 | @available(iOS 9, *) 151 | static func popupDialogWithText(text:String, options:[String]) -> APNotificationAlertView{ 152 | 153 | //-- Elements 154 | 155 | let view = UIView() 156 | 157 | view.translatesAutoresizingMaskIntoConstraints = false 158 | 159 | view.backgroundColor = UIColor(red: 0.9, green: 0.9, blue: 0.95, alpha: 1) 160 | 161 | let label = UILabel() 162 | 163 | label.translatesAutoresizingMaskIntoConstraints = false 164 | 165 | label.text = text 166 | 167 | label.textAlignment = .Center 168 | 169 | label.numberOfLines = 0 170 | 171 | label.minimumScaleFactor = 0.3 172 | 173 | let panel = UIStackView() 174 | 175 | panel.translatesAutoresizingMaskIntoConstraints = false 176 | 177 | panel.axis = .Horizontal 178 | 179 | panel.distribution = .FillEqually 180 | 181 | panel.alignment = .Fill 182 | 183 | var buttons = [UIButton]() 184 | 185 | var i = 0; 186 | for title in options { 187 | 188 | let button = UIButton(type: .System) 189 | 190 | button.tag = i 191 | 192 | button.translatesAutoresizingMaskIntoConstraints = false 193 | 194 | button.setTitle(title, forState: .Normal) 195 | 196 | panel.addArrangedSubview(button) 197 | 198 | buttons.append(button) 199 | 200 | i++ 201 | } 202 | 203 | //-- UI relations 204 | 205 | view.addSubview(panel) 206 | 207 | view.addSubview(label) 208 | 209 | APNotificationAlertView.addVerticalSnapConstraints(view, childView: panel, layoutAttribute: .Bottom, height: 35) 210 | 211 | APNotificationAlertView.addMarginConstraints(view, childView: label, margins: [50,20,0,-35]) 212 | 213 | 214 | let tempPopup = APNotificationAlertView.popupWithView(view) 215 | 216 | //-- Event Handlers 217 | 218 | for button in buttons{ 219 | button.addTarget(tempPopup, action: "onDialogButtonAction:", forControlEvents: .TouchUpInside) 220 | } 221 | 222 | return tempPopup 223 | 224 | } 225 | 226 | func onDialogButtonAction(button: UIButton){ 227 | 228 | if let completion = self.customCompletionHandler{ 229 | completion(button.tag) 230 | } 231 | 232 | } 233 | 234 | 235 | 236 | static func addLeftIconConstraints(superView:UIView, childView:UIView, values:[CGFloat]){ 237 | 238 | childView.addConstraint(NSLayoutConstraint( 239 | item: childView, 240 | attribute: NSLayoutAttribute.Width, 241 | relatedBy: NSLayoutRelation.Equal, 242 | toItem: nil, 243 | attribute: .NotAnAttribute, 244 | multiplier: 1, 245 | constant: values[1])) 246 | 247 | childView.addConstraint(NSLayoutConstraint( 248 | item: childView, 249 | attribute: NSLayoutAttribute.Height, 250 | relatedBy: NSLayoutRelation.Equal, 251 | toItem: nil, 252 | attribute: .NotAnAttribute, 253 | multiplier: 1, 254 | constant: values[2])) 255 | 256 | superView.addConstraints([ 257 | 258 | NSLayoutConstraint( 259 | item: childView, 260 | attribute: .Leading, 261 | relatedBy: .Equal, 262 | toItem: superView, 263 | attribute: .Leading, 264 | multiplier: 1, 265 | constant: values[0]), 266 | 267 | NSLayoutConstraint( 268 | item: childView, 269 | attribute: .CenterY, 270 | relatedBy: .Equal, 271 | toItem: superView, 272 | attribute: .CenterY, 273 | multiplier: 1, 274 | constant: 0), 275 | 276 | ]) 277 | 278 | } 279 | 280 | 281 | static func addVerticalSnapConstraints(superView:UIView, childView:UIView, layoutAttribute: NSLayoutAttribute, height:CGFloat){ 282 | 283 | childView.addConstraint(NSLayoutConstraint( 284 | item: childView, 285 | attribute: NSLayoutAttribute.Height, 286 | relatedBy: NSLayoutRelation.Equal, 287 | toItem: nil, 288 | attribute: .NotAnAttribute, 289 | multiplier: 1, 290 | constant: height)) 291 | 292 | superView.addConstraints([ 293 | 294 | NSLayoutConstraint( 295 | item: childView, 296 | attribute: .Leading, 297 | relatedBy: .Equal, 298 | toItem: superView, 299 | attribute: .Leading, 300 | multiplier: 1, 301 | constant: 0), 302 | 303 | NSLayoutConstraint( 304 | item: childView, 305 | attribute: .Trailing, 306 | relatedBy: .Equal, 307 | toItem: superView, 308 | attribute: .Trailing, 309 | multiplier: 1, 310 | constant: 0), 311 | 312 | NSLayoutConstraint( 313 | item: childView, 314 | attribute: layoutAttribute, 315 | relatedBy: .Equal, 316 | toItem: superView, 317 | attribute: layoutAttribute, 318 | multiplier: 1, 319 | constant: 0), 320 | 321 | ]) 322 | 323 | } 324 | 325 | static func addMarginSizeConstraints(superView:UIView, childView:UIView, values:[CGFloat]){ 326 | 327 | childView.addConstraint(NSLayoutConstraint( 328 | item: childView, 329 | attribute: NSLayoutAttribute.Width, 330 | relatedBy: NSLayoutRelation.Equal, 331 | toItem: nil, 332 | attribute: .NotAnAttribute, 333 | multiplier: 1, 334 | constant: values[2])) 335 | 336 | childView.addConstraint(NSLayoutConstraint( 337 | item: childView, 338 | attribute: NSLayoutAttribute.Height, 339 | relatedBy: NSLayoutRelation.Equal, 340 | toItem: nil, 341 | attribute: .NotAnAttribute, 342 | multiplier: 1, 343 | constant: values[3])) 344 | 345 | superView.addConstraints([ 346 | 347 | NSLayoutConstraint( 348 | item: childView, 349 | attribute: .Left, 350 | relatedBy: .Equal, 351 | toItem: superView, 352 | attribute: .Left, 353 | multiplier: 1, 354 | constant: values[0]), 355 | NSLayoutConstraint( 356 | item: childView, 357 | attribute: .Top, 358 | relatedBy: .Equal, 359 | toItem: superView, 360 | attribute: .Top, 361 | multiplier: 1, 362 | constant: values[1]), 363 | 364 | ]) 365 | 366 | } 367 | 368 | static func addHorizontalSnapConstraints(superView:UIView, childView:UIView, margins:[CGFloat], layoutAttribute: NSLayoutAttribute, width:CGFloat){ 369 | 370 | childView.addConstraint(NSLayoutConstraint( 371 | item: childView, 372 | attribute: NSLayoutAttribute.Width, 373 | relatedBy: NSLayoutRelation.Equal, 374 | toItem: nil, 375 | attribute: .NotAnAttribute, 376 | multiplier: 1, 377 | constant: width)) 378 | 379 | superView.addConstraints([ 380 | 381 | NSLayoutConstraint( 382 | item: childView, 383 | attribute: .Top, 384 | relatedBy: .Equal, 385 | toItem: superView, 386 | attribute: .Top, 387 | multiplier: 1, 388 | constant: margins[0]), 389 | 390 | NSLayoutConstraint( 391 | item: childView, 392 | attribute: .Bottom, 393 | relatedBy: .Equal, 394 | toItem: superView, 395 | attribute: .Bottom, 396 | multiplier: 1, 397 | constant: margins[1]), 398 | 399 | NSLayoutConstraint( 400 | item: childView, 401 | attribute: layoutAttribute, 402 | relatedBy: .Equal, 403 | toItem: superView, 404 | attribute: layoutAttribute, 405 | multiplier: 1, 406 | constant: 0), 407 | 408 | ]) 409 | 410 | } 411 | 412 | 413 | 414 | } 415 | -------------------------------------------------------------------------------- /demo/NotificationPopupExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // AppusNotificationPopupExample 4 | // 5 | // Created by Andrey Pervushin on 27.10.15. 6 | // Copyright © 2015 Andrey Pervushin. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /demo/NotificationPopupExample/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /demo/NotificationPopupExample/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /demo/NotificationPopupExample/Assets.xcassets/Logo.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "logo-1.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /demo/NotificationPopupExample/Assets.xcassets/Logo.imageset/logo-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appus-studio/Notification-AlertView/9b32629795d3ec3b59a0aec51eccecff4d64faca/demo/NotificationPopupExample/Assets.xcassets/Logo.imageset/logo-1.png -------------------------------------------------------------------------------- /demo/NotificationPopupExample/Assets.xcassets/LogoFront.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "logo_splash@3x.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /demo/NotificationPopupExample/Assets.xcassets/LogoFront.imageset/logo_splash@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appus-studio/Notification-AlertView/9b32629795d3ec3b59a0aec51eccecff4d64faca/demo/NotificationPopupExample/Assets.xcassets/LogoFront.imageset/logo_splash@3x.png -------------------------------------------------------------------------------- /demo/NotificationPopupExample/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /demo/NotificationPopupExample/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 34 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /demo/NotificationPopupExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /demo/NotificationPopupExample/LabelCollectionViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LabelCollectionViewCell.swift 3 | // NotificationPopupExample 4 | // 5 | // Created by Andrey Pervushin on 29.10.15. 6 | // Copyright © 2015 Andrey Pervushin. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class LabelCollectionViewCell: UICollectionViewCell { 12 | 13 | @IBOutlet weak var label: UILabel! 14 | 15 | } 16 | -------------------------------------------------------------------------------- /demo/NotificationPopupExample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // AppusNotificationPopupExample 4 | // 5 | // Created by Andrey Pervushin on 27.10.15. 6 | // Copyright © 2015 Andrey Pervushin. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | 12 | 13 | class ViewController: UIViewController { 14 | 15 | @IBOutlet var samplePopupView: UIView! 16 | 17 | @IBOutlet weak var valueLabel: UILabel! 18 | 19 | let dataSource = [ 20 | ["title":"Top", "action":"showViewFromTopAction"], 21 | ["title":"Text", "action":"showTextFromTopAction"], 22 | ["title":"Dialog", "action":"showDialogAction"], 23 | ["title":"Question", "action":"showQuestionAction"], 24 | ["title":"Bottom", "action":"showViewFromBottomAction"], 25 | ["title":"Hide", "action":"hideAnyPopupAction"] 26 | ] 27 | 28 | override func viewDidLoad() { 29 | super.viewDidLoad() 30 | 31 | self.samplePopupView.hidden = true 32 | } 33 | 34 | 35 | func showViewFromTopAction() { 36 | 37 | let popup = APNotificationAlertView.popupWithView(self.samplePopupView) 38 | 39 | popup.show() 40 | 41 | } 42 | 43 | func showViewFromBottomAction() { 44 | 45 | let popup = APNotificationAlertView.popupWithView(self.samplePopupView) 46 | 47 | popup.position = APNotificationAlertViewPosition.Bottom 48 | 49 | popup.height = 150 50 | 51 | popup.show() 52 | 53 | } 54 | 55 | 56 | func showTextFromTopAction() { 57 | 58 | let popup = APNotificationAlertView.popupWithText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.") 59 | 60 | popup.hideAfterDelay = 3 61 | 62 | popup.animationDuration = 1 63 | 64 | popup.show() 65 | 66 | } 67 | 68 | 69 | func showDialogAction() { 70 | 71 | let question = "Lorem ipsum dolor sit amet?" 72 | 73 | let buttonTitles = ["Yes", "No", "Oh No!"] 74 | 75 | let popup = APNotificationAlertView.popupDialogWithText(question, options: buttonTitles) 76 | 77 | popup.customCompletionHandler = { 78 | (index: Int) -> Void in 79 | 80 | APNotificationAlertView.hideAnimated(true) 81 | 82 | let alert = UIAlertController(title: "Taped button", message: "at index: \(index)", preferredStyle: .Alert) 83 | 84 | alert.addAction(UIAlertAction(title: "Ok", 85 | style: UIAlertActionStyle.Default, 86 | handler: { (action) -> Void in 87 | 88 | alert.dismissViewControllerAnimated(true, completion: nil) 89 | 90 | })) 91 | 92 | self.presentViewController(alert, animated: true, completion: nil) 93 | 94 | } 95 | 96 | popup.animationDuration = 1 97 | 98 | popup.show() 99 | 100 | } 101 | 102 | func showQuestionAction(){ 103 | 104 | let question = "Lorem ipsum dolor sit amet?" 105 | 106 | let popup = APNotificationAlertView.popupWithQuestion(question) 107 | 108 | popup.customCompletionHandler = { 109 | (index: Int) -> Void in 110 | 111 | APNotificationAlertView.hideAnimated(true) 112 | 113 | print("Taped button at index: \(index)") 114 | 115 | } 116 | 117 | popup.show() 118 | 119 | } 120 | 121 | func hideAnyPopupAction() { 122 | 123 | APNotificationAlertView.hideAnimated(true) 124 | 125 | } 126 | 127 | 128 | //Sample View 129 | 130 | @IBAction func hideFromPopupAction(sender: AnyObject) { 131 | 132 | APNotificationAlertView.hideAnimated(true) 133 | 134 | } 135 | 136 | @IBAction func valueSelectorAction(sender: UISlider) { 137 | 138 | self.valueLabel.text = "Lorem ipsum dolor \(sender.value)" 139 | 140 | } 141 | 142 | //CollectionView 143 | 144 | internal func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{ 145 | 146 | return dataSource.count 147 | 148 | } 149 | 150 | 151 | internal func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{ 152 | 153 | 154 | let cell = collectionView.dequeueReusableCellWithReuseIdentifier("LabelCollectionViewCell", forIndexPath: indexPath) as! LabelCollectionViewCell 155 | 156 | cell.label.text = self.dataSource[indexPath.row]["title"] 157 | 158 | return cell 159 | } 160 | 161 | internal func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){ 162 | 163 | let action = self.dataSource[indexPath.row]["action"]! 164 | 165 | self.performSelector( Selector(action) ) 166 | 167 | 168 | } 169 | 170 | 171 | 172 | 173 | 174 | } 175 | 176 | --------------------------------------------------------------------------------