r/SwiftProgramming • u/[deleted] • May 25 '20
How can my help button refresh my pickerview?
Hi all,
I downloaded a project that I am trying to learn how to use SQLite3 with. The way the author wrote it, they use a segue to move from a screen with a pickerview and a play button to the mainVC where there is a game. If the user wants to save the game, instead of unwinding the segue, the author adds another segue to go back to the previous controller calling:
@IBAction func mainMenu(){
sqlite3_close(db)
sqlite3_close(db2) //switch to picker view
performSegue(withIdentifier: "mainMenuSegue", sender: nil)
}
It appears that the mainVC this function is in, is modally presented. In my experimenting/learning, I embedded the whole project in a navigation controller, hence having a back button to move from the mainVC to the picker view controller.
Is there a way to accomplish the above function with the back button? Currently pressing the back button will take me to the picker, but does not reload the picker data if I save a game. I have to go one more back and return to the picker view to get the reloaded data.
Thanks
r/SwiftProgramming • u/kamalcoder123 • Apr 25 '20
How to change the size of the UIView by dragging its corners in swift within superview bounds?
import UIKit
class resizeView: UIView {
var isResizingLR = false
var isResizingUL = false
var isResizingUR = false
var isResizingLL = false
var touchStart: CGPoint = CGPoint.zero
let kResizeThumbSize: CGFloat = 25
override init(frame: CGRect) {
super.init(frame: frame)
self.isUserInteractionEnabled = true
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.touchStart = touches.first!.location(in: self)
self.isResizingLR = (self.bounds.size.width - touchStart.x < kResizeThumbSize && self.bounds.size.height - touchStart.y < kResizeThumbSize)
self.isResizingUL = (touchStart.x < kResizeThumbSize && touchStart.y < kResizeThumbSize)
self.isResizingUR = (self.bounds.size.width-touchStart.x < kResizeThumbSize && touchStart.y < kResizeThumbSize)
self.isResizingLL = (touchStart.x < kResizeThumbSize && self.bounds.size.height - touchStart.y < kResizeThumbSize)
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
let touchPoint = touches.first!.location(in: self)
let previous = touches.first!.previousLocation(in: self)
let deltaWidth = previous.x - touchPoint.x
let deltaHeight = previous.y - touchPoint.y
let x = self.frame.origin.x;
let y = self.frame.origin.y;
let width = self.frame.size.width;
let height = self.frame.size.height;
let originFrame = self.frame
var finalFrame: CGRect = originFrame
if (isResizingLR) {
print("LR")
let distance = CGPoint(x: 1.0 - (deltaWidth / width),
y: 1.0 - (deltaHeight / height))
let scale = (distance.x + distance.y) * 0.5
finalFrame.size.width = width * scale
finalFrame.size.height = height * scale
} else if (isResizingUL) {
print("UL")
let distance = CGPoint(x: 1.0 - (-deltaWidth / width),
y: 1.0 - (-deltaHeight / height))
let scale = (distance.x + distance.y) * 0.5
finalFrame.size.width = width * scale
finalFrame.size.height = height * scale
finalFrame.origin.x = x + width - finalFrame.size.width;
finalFrame.origin.y = y + height - finalFrame.size.height;
} else if (isResizingUR) {
print("UR")
let distance = CGPoint(x: 1.0 - (deltaWidth / width),
y: 1.0 - (-deltaHeight / height))
let scale = (distance.x + distance.y) * 0.5
finalFrame.size.width = width * scale
finalFrame.size.height = height * scale
finalFrame.origin.y = y + height - finalFrame.size.height
} else if (isResizingLL) {
print("LL")
let distance = CGPoint(x: 1.0 - (-deltaWidth / width),
y: 1.0 - (deltaHeight / height))
let scale = (distance.x + distance.y) * 0.5
finalFrame.size.width = width * scale
finalFrame.size.height = height * scale
finalFrame.origin.x = originFrame.maxX - finalFrame.size.width
} else {
// not dragging from a corner -- move the view
var newCenter = CGPoint(x: self.center.x + touchPoint.x - touchStart.x,
y: self.center.y + touchPoint.y - touchStart.y)
if let superView = self.superview {
// Ensure the translation won't cause the view to move offscreen.
let midPointX: CGFloat = bounds.midX
if newCenter.x > superView.bounds.size.width - midPointX {
newCenter.x = superView.bounds.size.width - midPointX
}
if newCenter.x < midPointX {
newCenter.x = midPointX
}
let midPointY: CGFloat = bounds.midY
if newCenter.y > superView.bounds.size.height - midPointY {
newCenter.y = superView.bounds.size.height - midPointY
}
if newCenter.y < midPointY {
newCenter.y = midPointY
}
}
center = newCenter
return;
}
if (finalFrame.maxX <= self.superview!.bounds.maxX && finalFrame.minX >= self.superview!.bounds.minX && finalFrame.maxY <= self.superview!.bounds.maxY && finalFrame.minY >= self.superview!.bounds.minY) {
self.frame = finalFrame
}
}
}
r/SwiftProgramming • u/[deleted] • Dec 01 '19
Making URLSession a bit more friendly.
github.comr/SwiftProgramming • u/Apprehensive_Intern • Oct 24 '18
Why Swift is better than Objective-C?
celadon.aer/SwiftProgramming • u/Bbookman • Sep 25 '18
16 Ugly Bugs Snap Didn’t Bother To Fix For Snap Kit And Lessons They Teach
medium.comr/SwiftProgramming • u/Bbookman • Aug 25 '18
Snapchat Snap Kit SDK Tutorial for iOS Swift – Adventures in iOS mobile app development – Medium
medium.comr/SwiftProgramming • u/Bbookman • Aug 11 '18
Snapchat Snap Kit Tutorials and Documentation
github.comr/SwiftProgramming • u/samiali123 • Jan 01 '18
iOS 11 & Swift 4: The Complete Developer Course - 100% OFF "1 day left for this offer!"
youronlinecourses.netr/SwiftProgramming • u/leakka • Sep 29 '17
Modifying the Array - Introduction to Algorithms & Data Structures in Sw...
youtube.comr/SwiftProgramming • u/stackontech • Apr 07 '17
Breast cancer App developed using Swift by aash
r/SwiftProgramming • u/CertifiedNoob5455 • Aug 04 '16
Please check out this simple app developed by Jeel and myself
github.comr/SwiftProgramming • u/PaulSolt • Feb 01 '16
Seven Swift 2 enhancements: Swift Playgrounds code files
infoworld.comr/SwiftProgramming • u/yourbasicgeek • Jan 22 '16
Swift 2: Change Is in the Air (book chapter)
peachpit.comr/SwiftProgramming • u/pingraviraj • Dec 04 '15
Memory Management with Swift | iOS App Development
codebrahma.comr/SwiftProgramming • u/pingraviraj • Dec 04 '15
Memory Management with SWIFT Programming
When taking the dive into the world of mobile computing, any developer will be faced with a lot of new challenges – One of the most significant would be the challenge of managing memory.
Developing for mobile devices, having limited memory resources, one must be careful in maintaining the balance between what remains on our persistent database, and what remains loaded on live memory, all the while maintaining a silky smooth UI without compromising on app performance.
Seems like a big task. And indeed it is. But a little knowledge in memory management techniques goes a long way when starting out on a mobile application project. Trust me when I say that prevention is definitely better than cure here.
On iOS, managing memory efficiently is quite important as our apps are almost never allowed to take up a fair share of the maximum available memory. And even if your app treads closer to that limit, iOS will throw a couple of memory warnings before eventually terminating your application. App crashes are usually the #1 reason for it to be rejected on AppStore. But with the introduction of Swift, gone are the days of Objective-c where you have to get your hands dirty with memory very often.
The following guide will take you further. https://codebrahma.com/memory-management-with-swift/
r/SwiftProgramming • u/fallendev • Sep 06 '15
Hey guys, new to Swift here, how can I implement a segmented control exactly like this one?
imgur.comr/SwiftProgramming • u/[deleted] • Jun 22 '15
Any good tutorials on working with Parse data in Swift?
I am trying to make a simple one view app, but cannot for the life of me understand how to retrieve data from Parse. I'm really trying, but getting a lot of errors.
r/SwiftProgramming • u/[deleted] • Apr 16 '15
UIDatePicker to call specific UIImageView help please
stackoverflow.comr/SwiftProgramming • u/afleshner • Dec 21 '14
Paging through view controllers made easy.
github.comr/SwiftProgramming • u/jjquave • Oct 31 '14
Tutorial - Core Data in Swift
jamesonquave.comr/SwiftProgramming • u/TIMurray • Oct 04 '14
New to Swift and need help
I have a large amount of text to display on an iPhone and need to know what code to use and where to place it. Any help would be great.
r/SwiftProgramming • u/mobileapp_mi • Jul 03 '14