Experiencing limit in number of UILabels added as subviews - swift

Unable to add more than three UILabels to a UIViewController’s view in the IPad Playgrounds app. Is it me or the system?
Simplified code to show the issue. Hardware is a 2018 iPad Pro running iOS 12.3.1 Playgrounds app 3.0. Using UIViews up to five can be added successfully.
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
let square50 = CGSize(width: 50, height: 50)
override func viewDidLoad() {
var myFrame = CGRect(origin: .zero, size: square50)
for index in 0...4 {
view.addSubview(UIView(frame: myFrame)) // fails at 6th!
(view.subviews[index] as! UIView).backgroundColor = .red
myFrame.origin.y += 80
}
}
}
PlaygroundPage.current.liveView = MyViewController()
With the index range set as shown the code worked as expected, displaying the set number of coloured rectangles. With the range increased to 0...5 the runtime stopped with the message “There was a problem encountered while running this playground. Check your code for mistakes”.

Just been able to test the code on Xcode 10.3 under OS X 10.16.6 on my iMac Retina 5k 27" late 2015. There is NO problem with the code and there is no short-range limit on the number of sub-views that can be created.
The problem rests with iOS Swift Playgrounds 3.0 running on an iPad Pro 12.9 inch 3rd-gen using iOS 12.3.1. This is therefore a bug!

Related

UITest tap not working on iOS 12.4 using iPhone X (works on iPhone 7)

Could this be related to SafeArea issues in iOS12.4 (and actually 12.2 as well)?
I use the following function to tap a view during my UITests.
func tapAtLocation(_ element: XCUIElement) -> Self {
let loc = element.coordinate(withNormalizedOffset: .init(dx: 0, dy: 0))
loc.tap()
return self
}
I try to tap at the location of a specific image.
So I get the image and trigger a tap
let myImage = App.images[myImageViewIdentifier].firstMatch
tapAtLocation(myImage)
It works on new iOS versions and also on iPhone 7 iOS 12.4 but not on iPhone X.
And I need it to work on iPhone X :)
What do you propose me to do? Maybe you have a nice debugging trick to see exactly where it tries to tap ?
ok ! After a day of fail and retry, a simple solution worked out!
func tapAtLocation(_ element: XCUIElement) -> Self {
let loc = element.coordinate(withNormalizedOffset: .init(dx: 0.5, dy: 0.5))
loc.tap()
return self
}
This works on all devices (iPhone X, 7 and 11) with iOS 12.4 and 13+

Xcode Storyboard Fail to show (render) ViewControllers (The agent crashed)

I'm running Xcode Version 10.2.1 (10E1001) on MacBook Pro 2016
Processor: 2.6 GHz Intel Core i7
Memory: 16 GB 2133 MHz LPDDR3
Graphic: Radeon Pro 450 2 GB and Intel HD Graphics 530 1536 MB
Storage: 256GB SSD
Free Storage: 45GB SSD
When i try to open storyboards i see a Storyboard with transparent ViewControllers but those ViewControllers already have UIViews and backgrounds but Xcode doesn't show,This remains for more than 20 minutes, then UIViews appear
This is how my #IBInspectable class looks like:
import Foundation
import UIKit
#IBDesignable
class BorderButton: UIButton {
#IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
layer.masksToBounds = cornerRadius > 0
}
}
override init(frame: CGRect) {
super.init(frame: frame)
}
}
Im getting error The agent crashed:
See picture below:
What i've done:
Cleaning build folder
Removing Derived Data
Close Xcode and re open
Free up ram
Solutions from this question
but none of above worked for me.

TraitCollectionDidChange behaves different for iphone X

In My case i am changing my layouts of the view depending on the traitCollection.horizontalSizeClass
Here is my Code snippet .
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if traitCollection.horizontalSizeClass == .regular {
// 2
NSLayoutConstraint.deactivate(compactConstraints)
NSLayoutConstraint.activate(regularConstraints)
// 3
socialMediaView.axis = .horizontal
} else {
// 4
NSLayoutConstraint.deactivate(regularConstraints)
NSLayoutConstraint.activate(compactConstraints)
socialMediaView.axis = .vertical
}
}
Every things working as directed in iphone 7 plus and iphone x in portrait-mode
and in landscape mode i want the rabbit image comes to left side and the stackview of all socialMedias axis will be horizontal
but in iphone X landscape mode its not coming while in phone 7 its coming .Check the below screen shots
Looking at your question and condition, I found a problem in your condition. you should check for the verticalSizeClass instead of horizontalSizeClass.
WHEN CHECK FOR HORIZONTAL SIZE CLASS.
IN PORTRAIT: All iPhone Devices has compact width, so every time, it will go to else condition and set the view properly.
IN LANDSCAPE: All iPhone Plus (iPhone 6s Plus, iPhone 7 Plus and iPhone 8 plus) Devices has Regular width and All other iPhone (iPhone 6s, 6SE, iPhone 7 and iPhone 8, iPhone X) Devices has Compact width, so for all plus devices it will works fine but not for others.
FOR PORTRAIT:
FOR LANDSCAPE:
For more, read official doc here
So, update your code to this.
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if traitCollection.verticalSizeClass == .regular {
NSLayoutConstraint.deactivate(compactConstraints)
NSLayoutConstraint.activate(regularConstraints)
socialMediaView.axis = .horizontal
} else {
NSLayoutConstraint.deactivate(regularConstraints)
NSLayoutConstraint.activate(compactConstraints)
socialMediaView.axis = .vertical
}
}
Try and share the results.

Using TVPosterImage in TVUIKit for tvOS 12

tvOS 12 has a new framework TVUIKit, which introduces the lockup views. The class I am interested in is TVPosterView, which is basically designed as such:
Swift 4.2
open class TVPosterView : TVLockupView { // One may use UIControl to implement it in iOS
public init(image: UIImage?)
open var image: UIImage? // default is nil
open var title: String?
open var subtitle: String?
}
In my storyboard I have added an UIView element, and rightly (at least I hope so. Yesterday the IB agent kept crashing!) changed its class to TVPosterView in Identity Inspector. then in my UIViewController I have defined:
#IBOutlet var aPosterView: TVPosterView!
override func viewDidLoad() {
super.viewDidLoad()
if let myIcon = UIImage(named: "icon.png") {
self.aPosterView = TVPosterView(image: myIcon)
self.aPosterView.title = "My Title"
self.aPosterView.subtitle = "A Sub Title"
}
else {
print("ERROR: I couldn't load the icon!")
}
}
}
It compiles without any warning. When I run it, it just shows the UIView white background, nothing changes. I did some tests trying to add an UIImageView, but they were all inconclusive (apart, off course, when I did set the image of UIImageView to self.aPosterView.image).
I am far from being an expert, I just started learning a couple of weeks ago. Any idea about what I am missing? I thought the concept was that once I initiated the class the framework was taking care of displaying the poster with the (optional) title and subtitles, also taking care of all nice animations!
Eventually I managed to make it working programmatically. I tested both TVPosterView and TVMonogramView (basically a round button). The following code works with Xcode 10 beta 5, on tvOS 12 beta 5:
Swift 4.2
import UIKit
import TVUIKit
class SecondViewController: UIViewController {
var myPoster = TVPosterView()
var myMonogram = TVMonogramView()
override func viewDidLoad() {
super.viewDidLoad()
myPoster.frame = CGRect(x: 100, y: 100, width: 550, height: 625)
myPoster.image = UIImage(named: "image1.png")
myPoster.imageView.masksFocusEffectToContents = true
myPoster.title = "Poster"
myPoster.subtitle = "This is the poster subtitle"
self.view.addSubview(myPoster)
var myName = PersonNameComponents()
myName.givenName = "Michele"
myName.familyName = "Dall'Agata"
myMonogram.frame = CGRect(x: 700, y: 100, width: 500, height: 475)
myMonogram.image = UIImage(named: "image2.png")
myMonogram.title = "Monogram"
myMonogram.subtitle = "This is the Monogram subtitle"
myMonogram.personNameComponents = myName
self.view.addSubview(myMonogram)
print(myMonogram.personNameComponents)
}
}
I didn't manage to scale the poster's image with scaleAspectFit, though. Also my first image was rounded with a transparency, and only choosing a frame size that perfectly fit the squared image plus the titles (so no aspect fit needed), the glowing effect became transparent on the corners. Otherwise the whole image was opaque, using its own (quite small) rounded corners.

SpriteKit SKCropNode displays all green on real device IOS 8.3

I'm using a simple SKCropNode with a standard XCode Swift Game Template.
Everything works fine in an emulator, but on a real iPhone 4S with iOS 8.3 I see just a green mask (although my shape is red) - no texture sprite is being displayed.
The funny thing is that on iPhone 5S with iOS 9 everything works fine too. So the problem is with iPhone 4S or iOS 8.3
Here's a Screenshot of a problem
I've could update my device to iOS 9, but I was thinking about supporting iOS 8 users too.
Is that fixable, or is that an Apple bug?
Here's the code to reproduce, it's based on a standard SpriteKit Game Template from XCode:
let center = CGPoint(x: self.frame.width*0.5, y: self.frame.height*0.5)
let sprite = SKSpriteNode(imageNamed:"Spaceship")
sprite.position = center
let mask = SKShapeNode(rectOfSize: CGSize(width: 200, height: 200))
mask.fillColor = SKColor.redColor()
mask.position = center
let crop = SKCropNode()
crop.maskNode = mask
crop.addChild(sprite)
self.addChild(crop)