Closed Smiller193 closed 6 years ago
Thank you for using TransitionButton. Can you please provide more information ? what's the issue exactly ? and if you have a demo example project with the issue it will help to provide a solution
I do have a demo project. I am using the transitionbutton to make the sequence of moving from the login screen/ sign up screen to the main controller easier.
It all starts with this login button that I created
lazy var loginButton: TransitionButton = {
let button = TransitionButton(type: .system)
button.setTitle("LOGIN", for: .normal)
button.setTitleColor(.white, for: .normal)
button.setupShadow2()
button.spinnerColor = .white
button.layer.cornerRadius = 5
button.titleLabel?.font = UIFont(name: "Futura", size: 14)
button.addTarget(self, action: #selector(handleLogin), for: .touchUpInside)
button.backgroundColor = UIColor.rgb(red: 44, green: 152, blue: 229)
return button
}()
When this button is pressed I run the function handleLogin
@objc func handleLogin(){
if self.emailTextField.text == "" || self.passwordTextField.text == "" {
let alertController = UIAlertController(title: "Error", message: "Please enter an email and a a password", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "Ok", style: .cancel, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
}else{
// SVProgressHUD.show(withStatus: "Logging in...")
loginButton.startAnimation()
AuthService.signIn(controller: self, email: emailTextField.text!, password: passwordTextField.text!) { [unowned self] (user) in
guard user != nil else {
// look back here
print("error: FiRuser dees not exist")
self.loginButton.stopAnimation()
return
}
// print("user is signed in")
UserService.show(forUID: (user?.uid)!) {[unowned self] (user) in
if let user = user {
User.setCurrent(user, writeToUserDefaults: true)
self.finishLoggingIn()
}
else {
print("error: User does not exist!")
return
}
}
}
}
}
Inside this function I start and stop the animation at appropriate times based on whether the login can occur or not.
Once all that is said and done i run this function which should stop the animation with a fade out similar to how it does in the example code.
func finishLoggingIn() {
// print("Finish logging in from LoginController")
let homeController = HomeViewController()
self.view.window?.rootViewController = homeController
self.loginButton.stopAnimation(animationStyle: .expand, completion: {
self.view.window?.makeKeyAndVisible()
})
}
The homeController is this one
import TransitionButton
class HomeViewController: UITabBarController,UITabBarControllerDelegate {
lazy var viewControllerList: [UIViewController] = {
let navController = UINavigationController(rootViewController: MainViewController())
navController.tabBarItem.image = UIImage(named: "icons8-home-page-50")?.withRenderingMode(.alwaysOriginal)
navController.tabBarItem.title = "Home"
navController.tabBarItem.selectedImage = UIImage(named: "icons8-home-page-filled-50")?.withRenderingMode(.alwaysOriginal)
let profileView = NewProfileVC()
let profileViewNavController = UINavigationController(rootViewController: profileView)
profileViewNavController.tabBarItem.image = UIImage(named: "icons8-User-50")?.withRenderingMode(.alwaysOriginal)
profileViewNavController.tabBarItem.title = "Profile"
profileViewNavController.tabBarItem.selectedImage = UIImage(named: "icons8-User Filled-50")?.withRenderingMode(.alwaysOriginal)
// let searchController = EventSearchController(collectionViewLayout: UICollectionViewFlowLayout())
let layout = UICollectionViewFlowLayout()
layout.sectionFootersPinToVisibleBounds = true
let searchVC = SearchVC()
let searchNavController = UINavigationController(rootViewController: searchVC)
searchNavController.title = "Search"
searchNavController.tabBarItem.image = UIImage(named: "icons8-search-50")?.withRenderingMode(.alwaysOriginal)
searchNavController.tabBarItem.selectedImage = UIImage(named: "icons8-search-filled-50")?.withRenderingMode(.alwaysOriginal)
searchNavController.tabBarItem.title = "Search"
let requestVC = RequestViewController()
let notificationView = NotificationsViewController()
requestVC.title = "Pending Friend Request"
notificationView.title = "Activity"
let pagerController = DTPagerController(viewControllers: [notificationView,requestVC])
pagerController.title = "Notifications"
pagerController.font = UIFont(name: "Avenir", size: 14)!
pagerController.selectedFont = UIFont(name: "Avenir-Medium", size: 14)!
pagerController.selectedTextColor = UIColor.black
pagerController.perferredScrollIndicatorHeight = 1.8
pagerController.preferredSegmentedControlHeight = 40
pagerController.scrollIndicator.backgroundColor = UIColor.black
let notificationNavController = UINavigationController(rootViewController: pagerController)
notificationNavController.tabBarItem.image = UIImage(named: "icons8-Notification-50")?.withRenderingMode(.alwaysOriginal)
notificationNavController.tabBarItem.selectedImage = UIImage(named: "icons8-Notification Filled-50")?.withRenderingMode(.alwaysOriginal)
notificationNavController.tabBarItem.title = "Notifications"
return [navController
,searchNavController,notificationNavController,profileViewNavController]
}()
let appDelegate = UIApplication.shared.delegate as! AppDelegate
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
viewControllers = viewControllerList
guard let items = tabBar.items else {
return
}
for item in items{
item.imageInsets = UIEdgeInsets(top: 4, left: 0, bottom: -4, right: 0)
}
//will set the defuat index to homeFeedController
}
}
It is a tabBarController which houses all the views that encompass my app. This one can't conform to the delegate that is required of the second view controller. Which causes the fade out animation to never occur. How would I accomplish that goal in this instance
@AladinWay
@AladinWay doesnt seem like it makes use of the library
Sorry, can you explain your point ?
I want to use the fade animation that comes with the button @AladinWay
The custom fade animation that comes with the library needs to be used when you present a view controller like self.present(secondVC, animated: true, completion: nil)
but in your case you are changing the root view controller of the window, then you need to create a custom animation like that:
button.stopAnimation(animationStyle: .expand, completion: {
guard let window = self.view.window else {return}
let secondVC = SecondViewController()
UIView.transition(with: window,
duration: 0.5,
options: .transitionCrossDissolve,
animations: {
window.rootViewController = secondVC
}, completion: nil)
})
So I am trying to accomplish this but the setup of my app is a tabBarController which contains the main controllers not just a simple UIViewController. How would I make that work in that case