Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // UIDashboardViewController.swift
- // Twingled
- //
- // Created by Tom Swindell on 12/05/2015.
- // Copyright (c) 2015 The App Developers. All rights reserved.
- //
- import Foundation
- import UIKit
- import CoreData
- func ==(lhs: CarouselButton, rhs: CarouselButton) -> Bool {
- return lhs.hashValue == rhs.hashValue
- }
- class CarouselButton: Hashable {
- var index = 0
- var avatarButton = UIButton()
- var unreadIndicator = UIView()
- var hashValue: Int {
- get {
- return "\(index)".hashValue
- }
- }
- func setUnreadMessageIndicator(visible: Bool) {
- if (visible) {
- if (unreadIndicator.superview == nil) {
- //draw circle
- let rect : CGRect = CGRectMake(0,0,48,48)
- unreadIndicator = UIView(frame: rect)
- avatarButton.addSubview(unreadIndicator)
- let circlePath = UIBezierPath(arcCenter: CGPoint(x: rect.width-8, y: 8), radius: CGFloat(4), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
- let shapeLayer = CAShapeLayer()
- shapeLayer.path = circlePath.CGPath
- //change the fill color
- let profileColor = UIColor.getProfileColorFromString(UserManager.SharedInstance.user!.profileColor)
- shapeLayer.fillColor = profileColor.CGColor
- //you can change the stroke color
- shapeLayer.strokeColor = UIColor.clearColor().CGColor
- unreadIndicator.layer.addSublayer(shapeLayer)
- }
- }
- else {
- unreadIndicator.removeFromSuperview()
- }
- }
- }
- class UIDashboardViewController: UIViewController {
- //MARK: Variables
- var pageViewController: UIPageViewController!
- var apiRequest = WebRequest()
- // var avatarButtons = [CarouselButton]()
- var avatarSet = Set<CarouselButton>()
- var currentPageIndex = 0
- var profileContentPages = [ProfileContentViewController]()
- var fetchResultsController: NSFetchedResultsController!
- var isChatOpen = false
- var hasOpenedProfile = false
- var pageVCinAnimation = false
- lazy var webStoryboard: UIStoryboard = {
- return UIStoryboard(name: "WebRequest", bundle: nil)
- }()
- lazy private var activityIndicator : CustomActivityIndicatorView = {
- let image : UIImage = UIImage(named: "spinner")!
- return CustomActivityIndicatorView(image: image)
- }()
- //top avatar buttons for easy access
- var avatarButtons: [CarouselButton] {
- get {
- var buttons = Array(self.avatarSet)
- buttons.sortInPlace({($0.index < $1.index) })
- return buttons
- }
- }
- //MARK: Outlets
- @IBOutlet weak var mainViewOutlet: UIView!
- @IBOutlet weak var twingledTitleOutlet: UIImageView!
- @IBOutlet weak var plusButtonOutlet: UIButton!
- @IBOutlet weak var editProfileButtonOutlet: UIButton!
- @IBOutlet weak var addTwingleButton: UIButton!
- @IBOutlet weak var avatarScrollView: UIScrollView!
- @IBOutlet weak var carousel: iCarousel!
- @IBOutlet weak var tutorialView: UIView!
- @IBOutlet weak var noConnectionsView: UIView!
- @IBOutlet weak var noConnectionsCopyLabel: UILabel!
- @IBOutlet weak var buySomeTwinglesCopyLabel: UILabel!
- @IBOutlet weak var largeTwingleGraphicTopConstraint: NSLayoutConstraint!
- @IBOutlet weak var largeTwingleGraphicHeightConstraint: NSLayoutConstraint!
- @IBAction func didTapAddTwingle(sender: AnyObject) {
- hasOpenedProfile = true
- let addTwingleStoryboard = UIStoryboard(name: "AddTwingle", bundle: nil)
- if let vc = addTwingleStoryboard.instantiateViewControllerWithIdentifier("addTwingle") as? AddTwingleViewController {
- vc.mode = .Recieve
- self.showDetailViewController(vc, sender: self)
- }
- }
- @IBAction func didTapBuyCodes(sender: AnyObject) {
- let vc = self.webStoryboard.instantiateInitialViewController() as! WebRequestViewController
- WebViewManager.SharedInstance.urlType = .BuyTwingles
- self.presentViewController(vc, animated: true, completion: nil)
- }
- @IBAction func didTapProfileButton(sender: AnyObject) {
- activityIndicator.startAnimating()
- UIApplication.sharedApplication().beginIgnoringInteractionEvents()
- }
- //MARK: Functions
- private func slideToPage(index: Int, completion: (() -> Void)?) {
- let count = ConnectionsManager.SharedInstance.connections.count
- if index < count {
- if index > currentPageIndex {
- if let vc = viewControllerAtIndex(index) {
- self.pageViewController.setViewControllers([vc], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: { (complete) -> Void in
- self.currentPageIndex = index
- completion?()
- })
- }
- } else if index < currentPageIndex {
- if let vc = viewControllerAtIndex(index) {
- self.pageViewController.setViewControllers([vc], direction: UIPageViewControllerNavigationDirection.Reverse, animated: true, completion: { (complete) -> Void in
- self.currentPageIndex = index
- completion?()
- })
- }
- }
- }
- }
- func reset() {
- if pageVCinAnimation{
- self.performSelector("reset", withObject: nil, afterDelay: 0.2)
- return
- }
- dispatch_async(dispatch_get_main_queue(), { () -> Void in
- for a in self.avatarSet {
- a.avatarButton.removeFromSuperview()
- }
- })
- if let vcs = pageViewController.viewControllers {
- for vc in vcs {
- vc.view.removeFromSuperview()
- vc.removeFromParentViewController()
- vc.dismissViewControllerAnimated(false, completion: nil)
- }
- }
- self.profileContentPages = [ProfileContentViewController]()
- self.pageViewController.dataSource = self
- self.pageViewController.delegate = self
- self.pageViewController.automaticallyAdjustsScrollViewInsets = false
- var index = 0
- for _ in ConnectionsManager.SharedInstance.connections {
- let vc = viewControllerAtIndex(index)
- vc?.view //forces view did load to be called
- ++index
- }
- let profileContentViewController = self.viewControllerAtIndex(0)
- if profileContentViewController != nil {
- self.pageViewController.setViewControllers([profileContentViewController!], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
- self.view.layoutIfNeeded()
- self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height)
- self.addChildViewController(pageViewController)
- self.mainViewOutlet.addSubview(pageViewController.view)
- self.pageViewController.view.center = self.mainViewOutlet.center
- self.pageViewController.didMoveToParentViewController(self)
- self.view.layoutIfNeeded()
- dispatch_async(dispatch_get_main_queue(), { () -> Void in
- for var i = 0; i < self.carousel.numberOfItems; i++ {
- self.carousel.itemViewAtIndex(i).removeFromSuperview()
- self.carousel.removeItemAtIndex(i, animated: false)
- }
- for a in self.avatarSet {
- a.avatarButton.removeFromSuperview()
- }
- self.avatarSet = Set<CarouselButton>()
- self.carousel.reloadData()
- })
- }
- if currentPageIndex > 0 && currentPageIndex < ConnectionsManager.SharedInstance.connections.count {
- slideToPage(currentPageIndex, completion: nil)
- selectAvatarButton(currentPageIndex)
- ChatManager.SharedInstance.delegate = self.profileContentPages[currentPageIndex].chatVC
- } else {
- slideToPage(0, completion: nil)
- self.selectAvatarButton(0)
- if self.profileContentPages.count > 0 {
- ChatManager.SharedInstance.delegate = self.profileContentPages[0].chatVC
- }
- }
- }
- func selectAvatarButton(index: Int) {
- // var avatarButtons: [CarouselButton] = Array(self.avatarSet)
- // avatarButtons.sortInPlace({($0.index < $1.index) })
- if avatarButtons.count > index && index >= 0 && ConnectionsManager.SharedInstance.connections.count > index {
- if ConnectionsManager.SharedInstance.connections.count > 0 {
- for a in avatarButtons {
- if a.index == index {
- let path = ConnectionsManager.SharedInstance.connections[index].avatar.imagePath
- if path != nil {
- let image = FileManager.SharedInstance.getImageFromDisk(path!)
- a.avatarButton.setImage(image!.mask(UIImage(named: "dashboardAvatarMask")!), forState: .Normal)
- a.avatarButton.setBackgroundImage(UIImage.createImageWithColor(UIColor.whiteColor(), size: CGSize(width: 41, height: 41)).mask(UIImage(named: "dashboardSelectedAvatarMask")!)!, forState: .Normal)
- }
- } else {
- a.avatarButton.setBackgroundImage(UIImage(), forState: .Normal)
- }
- }
- self.view.layoutIfNeeded()
- }
- }
- }
- func navigationToChat(senderId: String) {
- dispatch_async(dispatch_get_main_queue()) { () -> Void in
- let profileContentView = self.profileContentPages[self.currentPageIndex]
- profileContentView.chatVC.closeChatAction(self)
- // NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: "scrollToPage:", userInfo: senderId, repeats: false)
- }
- }
- func scrollToPage(timer: NSTimer) {
- let senderId = timer.userInfo as! String
- dispatch_async(dispatch_get_main_queue()) { () -> Void in
- for var i = 0; i < self.profileContentPages.count; i++ {
- let p = self.profileContentPages[i]
- if p.connection.account_id == senderId {
- self.carousel.scrollToItemAtIndex(i, animated: true)
- self.slideToPage(i, completion: { () -> Void in
- dispatch_async(dispatch_get_main_queue()) { () -> Void in
- self.changeTopBarAlpha(0.0, time: 0.3, animate: false, completion: { () -> () in
- UIView.animateWithDuration(0.2, delay: 1.2, options: UIViewAnimationOptions.CurveEaseIn, animations: { () -> Void in
- }, completion: { (complete) -> Void in
- dispatch_async(dispatch_get_main_queue(), { () -> Void in
- p.openChatView()
- })
- })
- })
- }
- })
- }
- }
- }
- }
- func viewControllerAtIndex(index : Int) -> UIViewController? {
- if((ConnectionsManager.SharedInstance.connections.count == 0) || (index >= ConnectionsManager.SharedInstance.connections.count)) {
- return nil
- }
- var profileContentViewController: ProfileContentViewController?
- for p in self.profileContentPages {
- if p.connection.account_id == ConnectionsManager.SharedInstance.connections[index].account_id {
- profileContentViewController = p
- }
- }
- if profileContentViewController == nil {
- profileContentViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ProfileContentViewController") as? ProfileContentViewController
- profileContentViewController!.connection = ConnectionsManager.SharedInstance.connections[index]
- var profiles = (profileContentViewController!.connection.profileImages.allObjects as! [ProfileImage]).sort({$0.modified.compare($1.modified) == NSComparisonResult.OrderedAscending})
- if profiles.count > 0 {
- let image = profiles[0].imagePath
- profileContentViewController!.imagePath = image
- }
- profileContentViewController!.pageIndex = index
- self.profileContentPages.append(profileContentViewController!)
- }
- self.changeTopBarAlpha(1.0, time: 0.33, animate: true, completion: nil)
- return profileContentViewController
- }
- func changeTopBarAlpha(alpha: CGFloat, time: NSTimeInterval, animate: Bool, completion: (() -> ())?) {
- if animate {
- UIView.animateWithDuration(time, animations: { () -> Void in
- self.twingledTitleOutlet.alpha = alpha
- self.plusButtonOutlet.alpha = alpha
- self.editProfileButtonOutlet.alpha = alpha
- self.addTwingleButton.alpha = alpha
- self.carousel.alpha = alpha
- }) { (complete) -> Void in
- if completion != nil {
- completion!()
- }
- }
- } else {
- self.twingledTitleOutlet.alpha = alpha
- self.plusButtonOutlet.alpha = alpha
- self.editProfileButtonOutlet.alpha = alpha
- self.addTwingleButton.alpha = alpha
- self.carousel.alpha = alpha
- if completion != nil {
- completion!()
- }
- }
- }
- func animateAlpha(notif: NSNotification) {
- if let alpha = notif.object as? CGFloat
- {
- self.changeTopBarAlpha(alpha, time: 0.33, animate: true, completion: nil)
- }
- }
- func changeAlpha(notif: NSNotification) {
- if let alpha = notif.object as? CGFloat
- {
- self.changeTopBarAlpha(alpha, time: 0.33, animate: false, completion: nil)
- }
- }
- typealias DeviceTokenCompletion = ((deviceToken: String?) -> Void)
- var deviceTokenCompletion: DeviceTokenCompletion?
- func registerForPush( completion: (deviceToken: String?) -> () ) {
- deviceTokenCompletion = completion
- let application = UIApplication.sharedApplication()
- if(application.respondsToSelector("isRegisteredForRemoteNotifications")) {
- application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: ([.Badge, .Sound, .Alert]), categories: nil));
- } else {
- application.registerForRemoteNotificationTypes([.Badge, .Sound, .Alert])
- }
- }
- func gotToken(notification: NSNotification) {
- var t: String?
- if let token = notification.object as? String {
- t = token
- }
- if deviceTokenCompletion != nil {
- deviceTokenCompletion!(deviceToken: t)
- }
- }
- //MARK: Class lifecycle
- override func viewDidLoad() {
- activityIndicator.center = view.center
- view.addSubview(activityIndicator)
- addObserversToViewController()
- let style = NSMutableParagraphStyle()
- style.lineSpacing = 5
- style.alignment = NSTextAlignment.Center
- let attributes = [NSParagraphStyleAttributeName : style]
- noConnectionsCopyLabel.attributedText = NSAttributedString(string: noConnectionsCopyLabel.text!, attributes:attributes)
- buySomeTwinglesCopyLabel.attributedText = NSAttributedString(string: buySomeTwinglesCopyLabel.text!, attributes:attributes)
- if DeviceType.IS_IPHONE_6 {
- largeTwingleGraphicTopConstraint.constant = 110
- } else if DeviceType.IS_IPHONE_6P {
- largeTwingleGraphicTopConstraint.constant = 130
- } else if DeviceType.IS_IPHONE_4_OR_LESS {
- largeTwingleGraphicHeightConstraint.constant = 130
- }
- view.layoutIfNeeded()
- UserManager.SharedInstance.dashboardNav = self.navigationController as? TwingledNavigationController
- if !NSUserDefaults.standardUserDefaults().boolForKey("hasSeenTutorial") {
- UIView.animateWithDuration(0.33, animations: { () -> Void in
- self.tutorialView.alpha = 1.0
- })
- }
- self.automaticallyAdjustsScrollViewInsets = false
- self.profileContentPages = [ProfileContentViewController]()
- // self.avatarButtons = [CarouselButton]()
- avatarSet = Set<CarouselButton>()
- self.carousel.type = .Linear
- self.carousel.scrollEnabled = false
- carousel.bounces = false
- carousel.ignorePerpendicularSwipes = true
- if let navController = self.navigationController as? TwingledNavigationController {
- navController.hideNavigationBar()
- }
- super.viewDidLoad()
- self.pageViewController = self.storyboard!.instantiateViewControllerWithIdentifier("PageViewController") as! UIPageViewController
- for v in self.pageViewController!.view.subviews {
- if let sub = v as? UIScrollView {
- sub.delegate = self
- }
- }
- registerForPush()
- }
- func registerForPush() {
- self.registerForPush { (deviceToken) -> () in
- if deviceToken != nil {
- self.loginToChat()
- UserManager.SharedInstance.uploadDeviceToken(UserManager.SharedInstance.Token!, deviceToken: deviceToken!, completion: {
- (success) -> () in
- if success {
- print("token uploaded")
- } else {
- print("token not uploaded")
- }
- })
- }
- }
- }
- func loginToChat() {
- FirebaseManager.sharedInstance.login(UserManager.SharedInstance.user!.email, password: UserManager.SharedInstance.user!.account_id) { (success, authData) -> () in
- if success {
- }
- }
- }
- func addObserversToViewController() {
- NSNotificationCenter.defaultCenter().addObserver(self, selector: "gotNewConnections", name: "gotNewConnections", object: nil)
- NSNotificationCenter.defaultCenter().addObserver(self, selector: "openingProfile", name: "openingProfile", object: nil)
- NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationBecameActive", name: "applicationBecameActive", object: nil)
- NSNotificationCenter.defaultCenter().addObserver(self, selector: "updatedConnection", name: "updatedConnection", object: nil)
- NSNotificationCenter.defaultCenter().addObserver(self, selector: "chatOpen", name: "chatOpen", object: nil)
- NSNotificationCenter.defaultCenter().addObserver(self, selector: "chatClosed", name: "chatClosed", object: nil)
- NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeBackgroundColor:", name: "changeBackgroundColor", object: nil)
- NSNotificationCenter.defaultCenter().addObserver(self, selector: "pageContentShown:", name: "pageContentShown", object: nil)
- NSNotificationCenter.defaultCenter().addObserver(self, selector: "animateAlpha:", name: "animateAlpha", object: nil)
- NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeAlpha:", name: "changeAlpha", object: nil)
- NSNotificationCenter.defaultCenter().addObserver(self, selector: "gotToken:", name: "GotDeviceID", object: nil)
- NSNotificationCenter.defaultCenter().addObserver(self, selector: "didTapLogout", name: "didTapLogout", object: nil)
- NSNotificationCenter.defaultCenter().addObserver(self, selector: "updatedConnectionProfile:", name: "updatedConnectionProfile", object: nil)
- }
- func gotNewConnections() {
- print("Got New Connections")
- dispatch_async(dispatch_get_main_queue()) { () -> Void in
- if ConnectionsManager.SharedInstance.connections.count == 0 {
- self.noConnectionsView.alpha = 1.0
- } else {
- self.noConnectionsView.alpha = 0.0
- }
- self.reset()
- }
- }
- func applicationBecameActive() {
- }
- override func viewWillDisappear(animated: Bool) {
- activityIndicator.stopAnimating()
- UIApplication.sharedApplication().endIgnoringInteractionEvents()
- super.viewWillDisappear(animated)
- }
- override func viewWillAppear(animated: Bool) {
- if(UserManager.SharedInstance.user == nil) {
- return
- }
- if !hasOpenedProfile {
- let connections = ConnectionsManager.SharedInstance.connections
- if connections.count == 0 {
- self.noConnectionsView.alpha = 1.0
- } else {
- dispatch_async(dispatch_get_main_queue(), { () -> Void in
- self.reset()
- self.carousel.scrollToItemAtIndex(0, animated: true)
- })
- }
- if ConnectionsManager.SharedInstance.connections.count == 0 {
- self.noConnectionsView.alpha = 1.0
- } else {
- self.noConnectionsView.alpha = 0.0
- }
- }
- super.viewWillAppear(animated)
- }
- override func viewDidAppear(animated: Bool) {
- super.viewDidAppear(animated)
- if(UserManager.SharedInstance.user == nil) {
- return
- }
- if !hasOpenedProfile {
- self.carousel.scrollToItemAtIndex(currentPageIndex, animated: true)
- selectAvatarButton(currentPageIndex)
- } else {
- hasOpenedProfile = false
- }
- }
- func changeBackgroundColor(notification: NSNotification) {
- self.mainViewOutlet.backgroundColor = notification.object as? UIColor
- }
- func didTapLogout() {
- hasOpenedProfile = false
- }
- func updatedConnection() {
- dispatch_async(dispatch_get_main_queue()) { () -> Void in
- self.reset()
- }
- self.carousel.scrollToItemAtIndex(currentPageIndex, animated: true)
- selectAvatarButton(currentPageIndex)
- }
- func pageContentShown(notification: NSNotification) {
- let index = notification.object as! Int
- self.currentPageIndex = index
- self.carousel.scrollToItemAtIndex(index, animated: true)
- }
- func chatOpen() {
- self.isChatOpen = true
- for v in self.pageViewController!.view.subviews {
- if let sub = v as? UIScrollView {
- sub.scrollEnabled = false
- }
- }
- }
- func chatClosed() {
- self.isChatOpen = false
- for v in self.pageViewController!.view.subviews {
- if let sub = v as? UIScrollView {
- sub.scrollEnabled = true
- }
- }
- }
- func openingProfile() {
- hasOpenedProfile = true
- }
- func updatedConnectionProfile(notification: NSNotification) {
- carousel.reloadData()
- }
- }
- extension UIDashboardViewController: UIPageViewControllerDelegate, UIPageViewControllerDataSource {
- func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
- var index = currentPageIndex
- index++
- if(index >= ConnectionsManager.SharedInstance.connections.count){
- return nil
- }
- return self.viewControllerAtIndex(index)
- }
- func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
- var index = currentPageIndex
- if(index <= 0){
- return nil
- }
- index--
- return self.viewControllerAtIndex(index)
- }
- func pageViewController(pageViewController: UIPageViewController, willTransitionToViewControllers pendingViewControllers: [UIViewController]) {
- pageVCinAnimation = true
- }
- func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
- pageVCinAnimation = false
- }
- }
- extension UIDashboardViewController: UIScrollViewDelegate {
- func scrollViewDidScroll(scrollView: UIScrollView) {
- if 0 == currentPageIndex && scrollView.contentOffset.x < scrollView.bounds.size.width {
- scrollView.contentOffset = CGPointMake(scrollView.bounds.size.width, 0)
- }
- if currentPageIndex == (ConnectionsManager.SharedInstance.connections.count - 1) && scrollView.contentOffset.x > scrollView.bounds.size.width {
- scrollView.contentOffset = CGPointMake(scrollView.bounds.size.width, 0)
- }
- }
- func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
- if 0 == currentPageIndex && scrollView.contentOffset.x <= scrollView.bounds.size.width {
- scrollView.contentOffset = CGPointMake(scrollView.bounds.size.width, 0)
- }
- if currentPageIndex == (ConnectionsManager.SharedInstance.connections.count - 1) && scrollView.contentOffset.x >= scrollView.bounds.size.width {
- scrollView.contentOffset = CGPointMake(scrollView.bounds.size.width, 0)
- }
- }
- }
- extension UIDashboardViewController: iCarouselDelegate, iCarouselDataSource {
- func numberOfItemsInCarousel(carousel: iCarousel!) -> Int {
- print("Number of items in the carousel: \(ConnectionsManager.SharedInstance.connections.count)")
- return ConnectionsManager.SharedInstance.connections.count
- }
- func carousel(carousel: iCarousel!, didSelectItemAtIndex index: Int) {
- self.selectAvatarButton(index)
- self.slideToPage(index, completion: nil)
- }
- func carouselDidEndDragging(carousel: iCarousel!, willDecelerate decelerate: Bool) {
- let index = carousel.currentItemIndex
- self.selectAvatarButton(index)
- self.slideToPage(index, completion: nil)
- }
- func carouselCurrentItemIndexDidChange(carousel: iCarousel!) {
- let index = carousel.currentItemIndex
- self.selectAvatarButton(index)
- //is new connection have unread message, if so disable indicator
- avatarButtons[index].setUnreadMessageIndicator(false)
- self.setCurrentConnectionTimestamp()
- }
- func setCurrentConnectionTimestamp() {
- //set timestamp
- let connection = ConnectionsManager.SharedInstance.connections[carousel!.currentItemIndex]
- ChatManager.SharedInstance.setMyTimestamp(connection.connection_id)
- }
- func carouselDidEndDecelerating(carousel: iCarousel!) {
- }
- func carousel(carousel: iCarousel!, viewForItemAtIndex index: Int, reusingView view: UIView!) -> UIView! {
- if UserManager.SharedInstance.user == nil {
- return UIView()
- }
- var b = view
- if let v = view as? UIButton {
- b = v
- // for sub in view.subviews {
- // sub.removeFromSuperview()
- // }
- // view.removeFromSuperview()
- } else {
- print("view is nil")
- }
- if index < ConnectionsManager.SharedInstance.connections.count {
- // var avatarButtons: [CarouselButton] = Array(self.avatarSet)
- // avatarButtons.sortInPlace({($0.index < $1.index) })
- let profile = ConnectionsManager.SharedInstance.connections[index]
- let avatar = profile.avatar
- b = UIButton(frame: CGRectMake(0, 0, 44, 44))
- for a in avatarButtons {
- if a.index == index {
- b = a.avatarButton
- }
- }
- let avatarButton = b as! UIButton
- let avatarImage = FileManager.SharedInstance.getImageFromDisk(avatar.imagePath!)
- if avatarImage != nil {
- avatarButton.setImage(avatarImage!.mask(UIImage(named: "dashboardAvatarMask")!), forState: .Normal)
- }
- b = avatarButton
- let carouselButton = CarouselButton()
- carouselButton.index = index
- carouselButton.avatarButton = b as! UIButton
- self.avatarSet.insert(carouselButton)
- self.view.layoutIfNeeded()
- avatarButtons[index].setUnreadMessageIndicator(true)
- }
- return b
- }
- func carousel(carousel: iCarousel!, valueForOption option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
- if (option == .Spacing) {
- return value * 1.1
- }
- return value
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement