make ipa exporting easier
This commit is contained in:
@@ -5,11 +5,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
var window: UIWindow?
|
||||
|
||||
func application(_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
||||
window = UIWindow(frame: UIScreen.main.bounds)
|
||||
window?.rootViewController = ViewController()
|
||||
window?.makeKeyAndVisible()
|
||||
return true
|
||||
}
|
||||
func application(
|
||||
_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
|
||||
) -> Bool {
|
||||
window = UIWindow(frame: UIScreen.main.bounds)
|
||||
window?.rootViewController = ViewController()
|
||||
window?.makeKeyAndVisible()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ enum PageTurnMode {
|
||||
}
|
||||
|
||||
class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
|
||||
var imageView = UIImageView()
|
||||
var images: [UIImage] = []
|
||||
var page = 0
|
||||
@@ -23,8 +22,6 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
var topTap: UITapGestureRecognizer!
|
||||
|
||||
let topBarView = UIView()
|
||||
let topBarLabel = UILabel()
|
||||
var topBarHeightConstraint: NSLayoutConstraint!
|
||||
|
||||
let pageTurnDropdownView = UIView()
|
||||
let pageTurnDropdownButton = UIButton()
|
||||
@@ -41,6 +38,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
}
|
||||
|
||||
func setup() {
|
||||
createTestFile()
|
||||
setupImageView()
|
||||
setupGestures()
|
||||
setupTopBar()
|
||||
@@ -111,24 +109,11 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
topBarView.isHidden = true
|
||||
view.addSubview(topBarView)
|
||||
|
||||
topBarHeightConstraint = topBarView.heightAnchor.constraint(equalToConstant: 0)
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
topBarView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
|
||||
topBarView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
topBarView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
topBarHeightConstraint,
|
||||
])
|
||||
|
||||
topBarLabel.text = "Menu"
|
||||
topBarLabel.textColor = .white
|
||||
topBarLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
topBarLabel.isHidden = true
|
||||
topBarView.addSubview(topBarLabel)
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
topBarLabel.centerXAnchor.constraint(equalTo: topBarView.centerXAnchor),
|
||||
topBarLabel.centerYAnchor.constraint(equalTo: topBarView.centerYAnchor),
|
||||
topBarView.heightAnchor.constraint(equalToConstant: 64),
|
||||
])
|
||||
|
||||
setupBackgroundColorDropdown()
|
||||
@@ -143,7 +128,8 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
topBarView.addSubview(backgroundColorDropdownButton)
|
||||
|
||||
backgroundColorDropdownButton.addTarget(
|
||||
self, action: #selector(toggleBackgroundColorDropdown), for: .touchDown)
|
||||
self, action: #selector(toggleBackgroundColorDropdown), for: .touchDown
|
||||
)
|
||||
|
||||
backgroundColorDropdownView.backgroundColor = UIColor.darkGray
|
||||
backgroundColorDropdownView.translatesAutoresizingMaskIntoConstraints = false
|
||||
@@ -169,13 +155,15 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
button.backgroundColor = .clear
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
button.addTarget(
|
||||
self, action: #selector(handleBackgroundColorOption), for: .touchDown)
|
||||
self, action: #selector(handleBackgroundColorOption), for: .touchDown
|
||||
)
|
||||
stackView.addArrangedSubview(button)
|
||||
}
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
backgroundColorDropdownButton.leadingAnchor.constraint(
|
||||
equalTo: topBarView.leadingAnchor, constant: 32),
|
||||
equalTo: topBarView.leadingAnchor, constant: 32
|
||||
),
|
||||
backgroundColorDropdownButton.centerYAnchor.constraint(
|
||||
equalTo: topBarView.centerYAnchor),
|
||||
backgroundColorDropdownButton.topAnchor.constraint(
|
||||
@@ -197,7 +185,6 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
stackView.trailingAnchor.constraint(
|
||||
equalTo: backgroundColorDropdownView.trailingAnchor),
|
||||
])
|
||||
|
||||
}
|
||||
|
||||
func setupPageTurnDropdown() {
|
||||
@@ -208,7 +195,8 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
topBarView.addSubview(pageTurnDropdownButton)
|
||||
|
||||
pageTurnDropdownButton.addTarget(
|
||||
self, action: #selector(togglePageTurnDropdown), for: .touchDown)
|
||||
self, action: #selector(togglePageTurnDropdown), for: .touchDown
|
||||
)
|
||||
|
||||
pageTurnDropdownView.backgroundColor = UIColor.darkGray
|
||||
pageTurnDropdownView.translatesAutoresizingMaskIntoConstraints = false
|
||||
@@ -234,13 +222,15 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
button.contentEdgeInsets = UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 0)
|
||||
button.addTarget(
|
||||
self, action: #selector(handlePageTurnOption), for: .touchDown)
|
||||
self, action: #selector(handlePageTurnOption), for: .touchDown
|
||||
)
|
||||
stackView.addArrangedSubview(button)
|
||||
}
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
pageTurnDropdownButton.trailingAnchor.constraint(
|
||||
equalTo: topBarView.trailingAnchor, constant: -32),
|
||||
pageTurnDropdownButton.leadingAnchor.constraint(
|
||||
equalTo: backgroundColorDropdownButton.trailingAnchor, constant: 32
|
||||
),
|
||||
pageTurnDropdownButton.centerYAnchor.constraint(
|
||||
equalTo: topBarView.centerYAnchor),
|
||||
pageTurnDropdownButton.topAnchor.constraint(
|
||||
@@ -262,7 +252,6 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
stackView.trailingAnchor.constraint(
|
||||
equalTo: pageTurnDropdownView.trailingAnchor),
|
||||
])
|
||||
|
||||
}
|
||||
|
||||
@objc func handlePageTurnOption(_ sender: UIButton) {
|
||||
@@ -314,9 +303,6 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
func toggleTopBar() {
|
||||
topBarView.isHidden.toggle()
|
||||
|
||||
topBarHeightConstraint.constant = !topBarView.isHidden ? 64 : 0 // You can adjust height
|
||||
topBarLabel.isHidden = topBarView.isHidden
|
||||
|
||||
pageTurnDropdownButton.isHidden = topBarView.isHidden
|
||||
backgroundColorDropdownButton.isHidden = topBarView.isHidden
|
||||
|
||||
@@ -391,49 +377,59 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
|
||||
}
|
||||
imageView.image = images[page]
|
||||
}
|
||||
}
|
||||
|
||||
func getImages() -> [UIImage] {
|
||||
let fileManager = FileManager.default
|
||||
let supportedExtensions = ["png", "jpg", "jpeg"]
|
||||
func getImages() -> [UIImage] {
|
||||
let fileManager = FileManager.default
|
||||
let supportedExtensions = ["png", "jpg", "jpeg"]
|
||||
|
||||
guard
|
||||
let documentsURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first
|
||||
else {
|
||||
print("Documents directory not found.")
|
||||
return []
|
||||
}
|
||||
|
||||
do {
|
||||
let contents = try fileManager.contentsOfDirectory(
|
||||
at: documentsURL, includingPropertiesForKeys: nil)
|
||||
|
||||
var images: [UIImage] = []
|
||||
|
||||
for file in contents {
|
||||
if supportedExtensions.contains(file.pathExtension.lowercased()) {
|
||||
print("Loading image: \(file.lastPathComponent)")
|
||||
if let image = UIImage(contentsOfFile: file.path) {
|
||||
images.append(image)
|
||||
} else {
|
||||
print("Failed to load image.")
|
||||
}
|
||||
} else {
|
||||
print("No image files found in Documents directory.")
|
||||
}
|
||||
}
|
||||
return images
|
||||
} catch {
|
||||
print("Error reading contents of Documents directory: \(error)")
|
||||
}
|
||||
guard
|
||||
let documentsURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first
|
||||
else {
|
||||
print("Documents directory not found.")
|
||||
return []
|
||||
}
|
||||
func createTestFile() {
|
||||
if let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
|
||||
.first
|
||||
{
|
||||
let fileURL = documentsURL.appendingPathComponent("dummy.txt")
|
||||
let data = ".".data(using: .utf8)!
|
||||
try? data.write(to: fileURL)
|
||||
|
||||
do {
|
||||
let contents = try fileManager.contentsOfDirectory(
|
||||
at: documentsURL, includingPropertiesForKeys: nil
|
||||
)
|
||||
|
||||
var images: [UIImage] = []
|
||||
|
||||
for file in contents {
|
||||
if supportedExtensions.contains(file.pathExtension.lowercased()) {
|
||||
print("Loading image: \(file.lastPathComponent)")
|
||||
if let image = UIImage(contentsOfFile: file.path) {
|
||||
images.append(image)
|
||||
} else {
|
||||
print("Failed to load image.")
|
||||
}
|
||||
} else {
|
||||
print("No image files found in Documents directory.")
|
||||
}
|
||||
}
|
||||
return images
|
||||
} catch {
|
||||
print("Error reading contents of Documents directory: \(error)")
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
func createTestFile() {
|
||||
let fileManager = FileManager.default
|
||||
if let documentsURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask)
|
||||
.first
|
||||
{
|
||||
do {
|
||||
let contents = try fileManager.contentsOfDirectory(atPath: documentsURL.path)
|
||||
if contents.isEmpty {
|
||||
let fileURL = documentsURL.appendingPathComponent("dummy.txt")
|
||||
let data = Data(".".utf8)
|
||||
try? data.write(to: fileURL)
|
||||
}
|
||||
} catch {
|
||||
print("Error reading directory contents: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user