I'm currently working on an iOS Today Extension and I'm having an issue with the extensions height. I've tried from scratch multiple times and I can't seem to figure out where the extra height is coming from. Where am I going wrong with AutoLayout. Thanks.
Storyboard View:
Scene View:
Size Inspector for View:
Results:
I also tried using the following and it said this:
override func viewDidLoad() {
super.viewDidLoad()
self.preferredContentSize = CGSizeMake(0, 100);
}
Edit: Could this be an iOS bug?
I've been beating my head against the desk over this for a while now but I've noticed a repeatable pattern on the simulator as well as a physical device. If I reset contents and settings on the simulator then run the Today Extension on it, it fills the entire space (even though it's not honoring my 100 height constraints), but as soon as I 'stop' running it, the view shrinks to 100 height and there is this extra padding at the bottom. Does anyone else experience this? Is this a bug or is this something that I am causing?
First run, while 'running':
After 'stopping' and subsequent 'runs'
Finally found the issue! Apple has absurd default margins, especially on the bottom. And the only way to change them is to implement the widgetMarginInsetsForProposedMarginInsets method. Here's the swift code:
func widgetMarginInsetsForProposedMarginInsets(defaultMarginInsets: UIEdgeInsets) -> UIEdgeInsets {
return UIEdgeInsetsZero
}
Related
I noticed something very strange with Xcode 9. When I'm on my main storyboard and I change the device selected to see the view controllers in the appropriate format, I've noticed that the width of my tableview on the viewDidLoad is wrong if the selected device on the storyboard is different that the device I deploy on. I have done tests and it seems that layout of the selected device on the storyboard is taken.
Does anyone has already experienced this issue?
This issue is also present on the beta version 9.1 of Xcode
I noticed the same problem when trying to apply a mask to my view's layer in order to round corners within a UITableViewCell. This answer did the trick for me.
In layoutSubviews(), call layoutIfNeeded() on any views where you need the true size at runtime. For my usage, it looks like this:
override func layoutSubviews() {
super.layoutSubviews()
print("cardView frame: \(cardView.frame)") // Storyboard size
cardView.layoutIfNeeded()
print("cardView frame: \(cardView.frame)") // Runtime device size
// Perform your layout here.
}
I hope this helps!
New iOS developer, have been following an iOS 9 course on Pluralsight and very simply need to be able to put some Labels in a ScrollView. All I did was select all of the labels and a button and clicked
Editor -> Embed In -> Scroll View
Here's what it looks like:
Which worked in the iOS 9 demo. I'm wondering if there is something different about iOS 10 that is not working. When I deploy to the app the labels show but you can't scroll. And yes I know how to scroll in the simulator.
I do see some warnings (which were present in the demo as well). I resolved a couple of them but still didn't work:
You can use "Reset to suggested constraint" option.Which is situated at right bottom corner in the storyboard.
You are not able to scroll because of the constraint so just override the viewDidLayoutSubviews() method into the respective viewController and provide the contentSize to the scrollView
override func viewDidLayoutSubviews() {
scrollView.contentSize = CGSize(width: self.view.frame.width, height: 1600.0)
}
In my application( for iphone and ipad),I have
1.MPmoviePLayer
2.tableView
3.TextView
4.CollectionView,all in a single view
The number of entries in the tableView and CollectionView may vary.The textView may also have variable content depending upon the main data.
All the four views are added as subviews for a scrollView.I want the scrollView to automatically resize its height depending on the content.I want the app run in iOS versions from iOS 7.Is there a way to do that?Using autolayout may work fine in iOS 8.But i think it will not work in iOS 7.Any suggestion is accepted.
Thanks in advance.
set below simple things in your appropriate method.
int height = CGRectGetHeight(tableview.frame)+CGRectGetHeight(CollectionView.frame)
+txtview.contentSize.height;
scrolview.contentsize = CGSizeMake(CGRectGetWidth(self.view.frame), height);
try this in your scrollViewDidScroll method...may be its work...
self.scrollview.contentSize = CGSizeMake(self.scrollview.contentSize.width,self.scrollview.contentSize.height);
I am trying to use the new auto size for my tableview. Im doing this:
tableView.rowHeight = UITableViewAutomaticDimension
I have a multiline-uilabel in my UITableViewCell with some constraints that is working splendid; the height of the rows is dynamic when I enter the tableview in both landscape and portrait! Awesome!
... but when I rotate the device the rows get the basic height (i.e. 44).
I added this row:
override func willAnimateRotationToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval)
{
self.tableView.reloadData()
}
And the problem vanishes. But should this really be necessary? There must be a better way to fix this?
Edit:
I just found out that the same problem occurs when I'm deleting a row in the table view like this:
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
Am I missing something here? Why aint this working out of the box?
Edit again:
I've now doing like this:
self.tableView.estimatedRowHeight = 44
tableView.rowHeight = UITableViewAutomaticDimension
Then when my data is fetched from API:
self.tableView.reloadData()
self.tableView.beginUpdates()
self.tableView.endUpdates()
This seems to cover all cases I've tested so far, but it seems really hacky! Without the begin/end-updates the cells are displaying some really funky heights at the first load. (But when rotating the device, the cells adjust their heights correctly.)
This all just seems so buggy. I've not found a single guide which cover these cases correctly.
I had a similar issue with rotation where the entire searchbar and tableView were displaced-down on very rotation from portrait to landscape and back. See-> Swift searchBar separates from top of tableView after searchController.active during rotation:
Swift searchBar separates from top of tableView after searchController.active during rotation
I pasted your override function i.e.:
override func willAnimateRotationToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval)
{
self.tableView.reloadData()
}
after viewDidLoad function and my problem disappeared. Don't know why. Glenn Tisman
According to the WWDC session from this year, if the cell already uses Autolayout, then it is supposed to automatically resize for you. It would do this by trying to call systemLayoutSizeFittingSize:(CGSize), or if you have not used autolayout, it would try to call sizeThatFits:(CGSize)
On thing to make sure of if you're supporting iOS7 as well is that setting tableView.rowHeight and tableView.estimatedRowHeight will cause strange behavior, and you would want to conditionally call one or the other, but not both, depending on which version of iOS the app is running on.
If you're having issues with the label in particular, you might also check that you're using the new "Automatic Preferred Max Layout Width" attribute for the UILabel (if you're in a storyboard, this is under the "Attributes" inspector) and that lines is set to '0'. See the documentation for more detail. See also "Behavior of Labels" in the iOS Interface Catalog for some caveats about mixing certain behaviors of UILabel and getting strange results.
Finally, you might see what is happening in the newly added rotation methods for size classes:
-willTransitionToSize:withTransitionCoordinator:
-willTransitionToTraitCollection:withTransitionCoordinator:
After trying this to dynamically resize my UITableView according to its contents size and failing:
self.tableViewPairedDevices.sizeToFit()
I tried this which worked fine as long as my Today Widget is tall enough to show it entirely:
var frame:CGRect = self.tableViewPairedDevices.frame
frame.size.height = self.tableViewPairedDevices.contentSize.height
self.tableViewPairedDevices.frame = frame
My next challenge was to get my iOS 8 Today Widget to resize according to the UITableView size, which I almost solved with:
self.preferredContentSize = self.tableViewPairedDevices.contentSize;
self.tableViewPairedDevices.setTranslatesAutoresizingMaskIntoConstraints(false)
The problem is that only one of them works at a time, if the UITableView gets resized, the extension's view doesn't, if I comment out the code that resizes the UITableView, the Today Extension gets resized successfully (the weird thing is that it knows what size the UITableView should be, even though the UITableView itself hasn't been resized) but the UITableView doesnt.
Any suggestions on how to achieve both things?
Thanks a lot!
I was able to make the above code work perfectly by disabling AutoLayout on the Extension's view
Don't forget UITableView has a Scroll inside. You need to define the height somehow.
I add a height constraint to the UITableView and then I updated that value to the contentSize.height
And that works.