- Worked on autolayout and did fixes for screen iphone 6s and iphone 11pro max resolutions

- 12-1 woka meeting
- Did Rnd on Container view. This will help for theming
- Made a custom class to add the child view and remove child view.
- Added Moon if the theme color is night
- added the Ca animation for the stars to show glowing effect
- Mapped all the stars with the delay time
- Handled the theme switch
This commit is contained in:
Bilal
2024-05-24 19:26:54 +05:30
parent 33180a55ab
commit 025aa41585
92 changed files with 1251 additions and 458 deletions

View File

@@ -2,109 +2,78 @@
// HomeVC.swift
// WOKA
//
// Created by Bilal on 03/05/2024.
// Created by Bilal on 24/05/2024.
//
import UIKit
class HomeVC: UIViewController {
protocol ChildViewControllerDelegate: AnyObject {
func didPressSwitchButton(from viewController: UIViewController)
}
@IBOutlet weak var gradientView: UIView!
@IBOutlet weak var cloud2: UIImageView!
@IBOutlet weak var cloud1: UIImageView!
@IBOutlet weak var liveTVView: UIView!
@IBOutlet weak var liveTvPlayer: UIView!
@IBOutlet weak var homeGrass: UIImageView!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var welcomeLabel: LocalisedElementsLabel!
var cloudMovingRight = false // Flag to track the direction of movement
var isMovingRight = false // Flag to track the direction of movement
var timer: Timer?
class HomeVC: UIViewController ,ChildViewControllerDelegate{
@IBOutlet weak var containerView: UIView!
var currentChildViewController: UIViewController?
var vm = HomeVM()
deinit{
timer?.invalidate()
}
override func viewDidLoad() {
super.viewDidLoad()
vm.vc = self
vm.initView()
moveCloudView()
moveLiveTVView()
// Initialize the first child view controller
let sb = UIStoryboard(name: "Theme", bundle: nil)
if let firstVC = sb.instantiateViewController(withIdentifier: "ThemeOneVC") as? ThemeOneVC {
add(asChildViewController: firstVC)
firstVC.delegate = self
}
}
func moveLiveTVView() {
UIView.animate(withDuration: 6, delay: 0, options: [.allowUserInteraction], animations: {
let margin: CGFloat = 30
let screenWidth = self.view.frame.width
let viewWidth = self.liveTVView.frame.width
let maxX = screenWidth - margin - viewWidth / 2
let minX = margin + viewWidth / 2
if self.isMovingRight {
self.liveTVView.center.x = maxX // Move to the right
} else {
self.liveTVView.center.x = minX // Move to the left
}
}, completion: { _ in
self.isMovingRight.toggle() // Toggle the direction for the next iteration
self.moveLiveTVView() // Recursively call moveLiveTVView to create a continuous animation
})
}
func moveCloudView() {
UIView.animate(withDuration: 23, delay: 0, options: [], animations: {
if self.cloudMovingRight {
print("right")
self.cloud2.center.x += 140 // Move to the right
self.cloud1.center.x -= 140 // Move to the right
} else {
print("left")
self.cloud2.center.x -= 140 // Move to the left
self.cloud1.center.x += 140 // Move to the left
}
}, completion: { _ in
self.cloudMovingRight.toggle() // Toggle the direction for the next iteration
self.moveCloudView() // Recursively call moveView to create a continuous animation
})
}
// Define a function to customize tab bar item icon size
func customizeTabBarItemIconSize() {
// Get a reference to the tab bar controller
if let tabBarController = self.tabBarController {
// Loop through each tab bar item
for item in tabBarController.tabBar.items! {
// Adjust the image insets to increase the icon size
item.imageInsets = UIEdgeInsets(top: 2, left: -5, bottom: -8, right: -5)
item.titlePositionAdjustment.vertical = CGFloat(8)
}
func didPressSwitchButton(from viewController: UIViewController) {
if viewController is ThemeOneVC {
switchToViewController(withIdentifier: "ThemeTwoVC")
} else if viewController is ThemeTwoVC {
switchToViewController(withIdentifier: "ThemeOneVC")
}
}
@IBAction func barButtonTapped(_ sender: UIButton) {
self.sideMenuController?.revealMenu()
private func switchToViewController(withIdentifier identifier: String) {
let sb = UIStoryboard(name: "Theme", bundle: nil)
let newVC = sb.instantiateViewController(withIdentifier: identifier)
if let newVC = newVC as? ThemeOneVC {
newVC.delegate = self
} else if let newVC = newVC as? ThemeTwoVC {
newVC.delegate = self
}
print("Switching to view controller with identifier \(identifier)")
replaceCurrentChildViewController(with: newVC)
}
}
class NavigationController: UINavigationController {
open override var childForStatusBarHidden: UIViewController? {
return self.topViewController
private func add(asChildViewController viewController: UIViewController) {
print("Adding child view controller: \(viewController)")
addChild(viewController)
viewController.view.frame = containerView.bounds
containerView.addSubview(viewController.view)
viewController.didMove(toParent: self)
currentChildViewController = viewController
}
open override var childForStatusBarStyle: UIViewController? {
return self.topViewController
private func remove(asChildViewController viewController: UIViewController) {
print("Removing child view controller: \(viewController)")
viewController.willMove(toParent: nil)
viewController.view.removeFromSuperview()
viewController.removeFromParent()
}
private func replaceCurrentChildViewController(with newViewController: UIViewController) {
// Clear previous views
containerView.subviews.forEach { $0.removeFromSuperview() }
// Remove current child view controller if exists
if let currentVC = currentChildViewController {
remove(asChildViewController: currentVC)
}
// Add new child view controller
add(asChildViewController: newViewController)
}
}