First, the easiest way how to keep some UIImageView centered is to either bound it using autolayout to all sides of the superview and set contentMode to "Center" as Sudhin Davis advices, or to set "Align Horizontal Center in Container" and "Align Vertical Center in Container" of it to 0 (leaving height and width not-set or removed at build time).
But if you want to create a splash screen ViewController which will be 'prolonging' your 'native splash screen' image presentation while you do some work, then you could use something like:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
imageView?.image = UIImage(named: splashScreenImageName())
}
Where imageView
is a simple UIImageView outlet bound to all sides of it's superview and splashScreenImageName()
is a func that provides Splash screen image name using one of adviced approaches from answers to this question.
I usually use something like this:
func splashScreenImageName() -> String {
// Construct the name.
var splashScreenImageName = "LaunchImage";
if (UIDevice.isIPhone6Plus) {
splashScreenImageName += "-800-Portrait-736h";
}
else if (UIDevice.isIPhone6) {
splashScreenImageName += "-800-667h";
}
else if(UIDevice.isIPhone5) {
splashScreenImageName += "-700-568h";
}
else if (UIDevice.isIPad) {
splashScreenImageName += "-700-Landscape";
}
else {
splashScreenImageName += "-700";
}
return splashScreenImageName;
}
Pros:
- use are reusing your splash screen image. Meaning that you don't need to add another 3 .jpgs for iPhone and 2 for iPad (for each orientation) into bundle and keep them in sync with 'native splash screen'.
- therefore you are lowering bundled app size.
- the image received this way will 100% match with the one that was displayed during 'native splash screen' presentation. So not 'jumping' should appear.