Floating UIView on UITableView broken in iOS6 - xcode

In my app i have UIView that floats at the top of a UITableView (Visualise:Attached to the bottom of the navigation Bar), under iOS5 i was enabling it to float at the top using these lines of code in scrollViewDidScroll
// get the table and buttonView bounds
CGRect tableBounds = self.tableView.bounds;
CGRect buttonViewFrame = self.buttonView.frame;
// make sure the buttonView at the table's original x and y as the content moves
self.buttonView.frame = CGRectMake(tableBounds.origin.x,tableBounds.origin.y,buttonViewFrame.size.width,buttonViewFrame.size.height);
This however no longer seems to work in iOS6, does anyone know why or how to fix the problem? I'm supporting iOS5 and above.
Having looked through the iOS6 release notes i found this...
Note that you can make a subview of the scroll view appear to float (not scroll) over the other scrolling content by creating constraints between the view and a view outside the scroll view’s subtree, such as the scroll view’s superview.
How would I set this up in code as Im not using AutoLayout in storyboards as I'm still supporting iOS5. It would also be great if anyone can enlighten me as to why the code i was using in iOS5 no longer works in 6.

Related

How to fix scrollable content size ambiguity in xcode 11 using auto layout beta 7 UIKIT

When using Auto Layout, I am unable to set up a simple UIScrollView in my view controller in Xcode 11 beta 7. I know that I must constrain the scroll view to the edges, and then set the scroll view width and height equal to the width and height of the entire view that contains the scroll view. However, I am not getting the option to set equal widths and heights when I attempt to do so.
When I do the right-click-drag from the scroll view to the entire main view, I get the following options:
Leading Space to Safe Area
Top Space to Safe Area
Trailing Space to Safe Area
Bottom Space to Safe Area
Center Horizontally in Safe Area
Center Vertically in Safe Area
In other videos, there is an "Equal Widths" and "Equal Heights" option that I don't seem to have.
Am I doing something wrong, or did Apple change the way scroll views work in Xcode 11?
I'm using beta 7 currently
I was finally able to successfully add a UIScrollView using storyboards in Xcode Version 11.0 (11A420a) after much trial and error.
You can add the scroll view directly to the root UIView of the VC or, if you needed to, add it to another UIView under the root view as needed by your UI Design. Constrain the UIScrollView parents normally for whatever your needs are.
Here is the key : when you add the UIScrollView to the storyboard, click on the Size Inspector with the UIScrollView selected. You have to UNCHECK the box that says "Content Layout Guides".
If you do this you can set the scroll view's contraints normally (I did 0-0-0-0 to superview). Then I added a UIView to the scrollview and set it's constraints to 0-0-0-0 and a height of 900 (which is what I wanted).
This will give you constraint errors in red when you set them. They will be fixed by setting the width of the UIView equal to the width of the UIScrollView.
Set the UIView width equal to the width of the UIScrollView view by Ctrl-right clicking on the UIView, dragging to the UIScrollView, and selecting the "Equal Widths" option. This should get rid of your constraint errors.
You actually can then go back to the UISCrollView Size Inspector and check the "Content Layout Guides" checkbox, no constraint errors will appear.
Disable the content layout guides in scrollview properties.
Hope it helps.. :)

UIScrollView without AutoLayout shows horizontal scroll Indicator in iOS 6 but not in iOS 7

I spent several days trying to see the working UIScrollView horizontal scroll indicator (without AutoLayout) on iOS7 (on iPad). But without success.
Has anyone fixed such bug?
My project is simple and running iOS5 and iOS6 without troubles.
I found out, that on iOS7 height of the scroll indicator image is always zero:
UIImageView * scrollBar = [[scrollView subviews] lastObject];
if (scrollBar != nil)
{
PrintRect(#"FRAME", scrollBar.frame);
PrintRect(#"BOUNDS", scrollBar.bounds);
}
Result for iOS7:
FRAME x:0.000000 y:54.000000 w:338.000000 h:0.000000
BOUNDS x:0.000000 y:0.000000 w:338.000000 h:0.000000
but for iOS6:
FRAME x:0.000000 y:47.000000 w:338.000000 h:7.000000
BOUNDS x:0.000000 y:0.000000 w:338.000000 h:7.000000
So the height scroll bar image on iOS7 is equal to zero.
It's possible to change the height, but only for a quick time because during drugging the height becames zero again.
I was stuck on something similar. I am doing the CS193P course on iTunes and there was this scrollView exercise - Imaginarium. Basically it's just a UIImageView embedded in a UIScrollView. I was having the same problem that the scroll indicators were not being displayed (with Autolayout turned off)
I looked up the header file for UIScrollView in the documentation and there is this property in scrollView called scrollIndicatorInsets:
The distance the scroll indicators are inset from the edge of the scroll view.
#property(nonatomic) UIEdgeInsets scrollIndicatorInsets
It goes on to say that the default value is UIEdgeInsetsZero!! So I created a UIEdgeInset using UIEdgeInsetsMake (see documentation). Then in viewDidLoad I set this UIEdgeInsets to be my scrollView's scrollIndicatorInsets, after which my indicators appeared when I scrolled.
Hope this works for you too.

UITableView Stretching Issue

I have a UIViewController that has an image and label at the top followed by a UITableView. In the IB it looks perfect, but when I run the application in the simulator the UITableView is stretching and taking up the entire screen.
I've turned off all autosizing and set all of the values for stretching to 0, but it's still taking up the entire screen. I even tried some advice I saw on another post which suggested putting the UITableView in a UIView that was sized, but that did not work either.
Any suggestions on how to stop the UITableView from resizing and filling the screen? I am running XCode 4.2.1 with iOS5.
You can give frame size to your tableView like this-
1) make your tableView's IBOutlet property in .h class, and synthesize in .m class.
2) connect it in Xib.
3) than in your .m class place this code in viewDidLoad-
tblView.frame = CGRectMake(0.0f, 30.0f, 320.0f, 50.0f); // you can give any size to your table

Autoresize the root view when device is rotated

I am developing PDF reader. I am facing problem while rotating the simulator. What I am doing is, when view is loaded by the ViewController(i.e. in the loadView), I am creating the UIScrollView which contains UIImageView and UIView of the same size(i.e. size of the PDF page). It is working perfectly in the portrait mode. But when I rotate the simulator in the landscape mode, the view is not autoresized according to device. I have tried
self.view.autoresizesSubviews = YES;
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
in the viewDidLoad() of the ViewController
But it's not working. I am confused how the above two properties work. I guess these properties will autoresize the UIScrollView to the size of root view in which I am loading UIScrollView. But what should be done to autoresize the main view in which UIScrollView is loaded??
I've experienced the same problem when trying to utilise the auto resizing methods. So, I hope this will help. (P.S. I'm assuming you're creating the UI programmatically and not via IB)
So have you tried this?
Inside your viewcontroller add the following:
// Set the View Controller to fit the whole screen.
-(BOOL)wantsFullScreenLayout{
return YES;
}
Inside the loadView method amend your scrollView to:
// set the initial size of your scrollView object.
[scrollView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
// Set the auto resizing attributes.
[scrollView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
In addition to this you might need to set the autoresizingmask margins for either the UIView or UIImageView depending on the type of layout you require when the device is rotated.
This is late reply... It may help if you didn't Fix it yet.
When you create any app in portraid mode and if you want it to rotate (resize) to landscape mode, you should do it in User Interface Builder or .xib (or in Storyboard iPad or iPhone)file.
So to check or to check rotate in the Simulator:
Go to "USER INTERFACE BUILDER", or ".XIB" (or "Storyboard iPad or iPhone") file.
Then select "UIImageView" and go to "SHOW THE ATTRIBUES INSPECTOR".
In the fourth tab (Attributes Inspector) set the mode to “Aspect Fit”, and in the third tab (Size Inspector) and in the fifth tab (Size Inspector) set the autosizing attributes to the following:
Set the arrows to all directions. Sorry can't load image.
Do the same for "UIView" (3).
Before you move on, you can double check that you’ve gotten all of the autosizing attributes right by selecting the Detail View Controller, and changing the orientation from Portrait to Landscape: Sorry can't load image for now...
You can Check or Change to "Landscape or Portrait" on the top right side "Simulated Metrics" select under "Size" the "Orientation".
If something isn’t right, don't worry: Just change it back to Portrait and double check the settings.

UIPopovercontroller detached from UIButton

I'm running into a problem with a detached UIPopovercontroller and am hoping someone has seen this behavior before.
My app runs in Landscape mode and offers a number of popover elements using the presentPopoverFromRect call. Some are launched from within the top view while others are presented from a view buried deep in the display. The popovers seem to work fine if the popover is presented from the upper 2/3rds of the iPad's display however when attempting to launch a popover from the bottom 1/3 of the display the popover is displayed detached from the UIButton. The x coordinate appears to be correct, however the y coordinate of the popover tends to be in the middle or top of the iPad screen.
I've played around with presenting the popover using a fixed position by creating a CGRect object in the lower 1/3 of the display but when the iPad renders the popover it either renders the popover in the upper 2/3rd of the view or the very bottom of the screen (if I force the CGRect value to a large y value).
At this point I'm out of ideas and hoping someone on the forum has seen this or can make suggestions as to what to try.
Thanks for any and all help,
Wes
I was able to fix my issue and thought that I'd share my solution incase someone else has the same problem.
The solution was to add a call to set the popover size BEFORE calling presentPopoverFromRect.
[mySettingsPopoverController setPopoverContentSize:CGSizeMake(320, 320) animated:YES];
[mySettingsPopoverController presentPopoverFromRect:sender.frame inView:self.navigationButtonsView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Before, I wasn't setting the popover content size prior to presenting the popover. In the viewDidAppear method of the viewcontroller of the popover I was resizing the popover to size to the tableview in the popover. Apparently by not setting the popovercontentsize before presenting the popover you get undefined behavior including the possibility of having the popover detach from the element that it is suppose to be attached to.
Wes

Resources