- Added the bottom background in autolayout. - Added cloud 1 and cloud 2 which will animate left to right and vice versa. - Handled bottom Tabbar Height dyamically. Handled this via logic of safe area.
88 lines
3.1 KiB
Swift
88 lines
3.1 KiB
Swift
//
|
|
// HomeVC.swift
|
|
// WOKA
|
|
//
|
|
// Created by Bilal on 03/05/2024.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class HomeVC: UIViewController {
|
|
|
|
@IBOutlet weak var gradientView: UIView!
|
|
@IBOutlet weak var cloud2: UIImageView!
|
|
@IBOutlet weak var cloud1: UIImageView!
|
|
|
|
var isMovingRight = false // Flag to track the direction of movement
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
// let color1 = #colorLiteral(red: 0.3490196078, green: 0.8156862745, blue: 0.9960784314, alpha: 1)
|
|
// let color2 = #colorLiteral(red: 0.6901960784, green: 0.2745098039, blue: 0.7568627451, alpha: 1)
|
|
// gradientView.applyGradient(colors: [color1, color2], startPoint: CGPoint(x: 0, y: 0), endPoint: CGPoint(x: 0.8, y: 0))
|
|
// Do any additional setup after loading the view.
|
|
// customizeTabBarItemIconSize()
|
|
// moveIt(cloud2,10)
|
|
moveView()
|
|
}
|
|
|
|
func moveView() {
|
|
UIView.animate(withDuration: 23, delay: 0, options: [.autoreverse], animations: {
|
|
if self.isMovingRight {
|
|
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.isMovingRight.toggle() // Toggle the direction for the next iteration
|
|
self.moveView() // Recursively call moveView to create a continuous animation
|
|
})
|
|
}
|
|
|
|
func moveIt(_ imageView: UIImageView,_ speed:CGFloat) {
|
|
let speeds = speed
|
|
let imageSpeed = speeds / view.frame.size.width
|
|
let averageSpeed = (view.frame.size.width - imageView.frame.origin.x) * imageSpeed
|
|
UIView.animate(withDuration: TimeInterval(averageSpeed), delay: 0.0, options: .curveLinear, animations: {
|
|
imageView.frame.origin.x = self.view.frame.size.width
|
|
}, completion: { (_) in
|
|
imageView.frame.origin.x = -imageView.frame.size.width
|
|
self.moveIt(imageView,speeds)
|
|
})
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
}
|
|
}
|
|
|
|
@IBAction func barButtonTapped(_ sender: UIButton) {
|
|
self.sideMenuController?.revealMenu()
|
|
}
|
|
|
|
}
|
|
|
|
|
|
class NavigationController: UINavigationController {
|
|
|
|
open override var childForStatusBarHidden: UIViewController? {
|
|
return self.topViewController
|
|
}
|
|
|
|
open override var childForStatusBarStyle: UIViewController? {
|
|
return self.topViewController
|
|
}
|
|
}
|