IB Instantiated UIScrollView not scrolling - ios

Yes, I have set the contentsize. When I do an NSLog of the contentsize I get a height of 0 and a width of 0 which is a little confounding. It seems like my scrollview doesn't actually exist.
I think I'm setting up the scrollview wrong.
In IB I have a viewcontroller subclass that has a scrollview, inside the scrollview are other labels/views/etc.
Does the scrollview need to have a single subview that manages the "actual" subviews or something?
When I run an NSLog on the scrollview it comes up with this:
Scrollview: <UIScrollView: 0x81b2960; frame = (0 0; 0 0); clipsToBounds = YES; autoresize = TM+BM; gestureRecognizers = <NSArray: 0x81b2dc0>; layer = <CALayer: 0x81b7390>; contentOffset: {0, 0}>

The scroll view does not need to have a single master subview. I'd bet dollars to donuts you have forgotten to hook up the IBOutlet that should point to your UIScrollView in the xib file.

Okay, I figured it out, I needed to have the contentsize code in a viewDidAppear method not in a viewDidLoad method. It's weird because the other changes were being made, just not this one. Go figure

Related

iOS UICollectionView ConsoleLog Caution when Item Width is bigger than CollectionView width

I'm using UICollectionView for my project and I put bigger Item than collectionView width to hide selectionButton/DeleteButton and show them when Edit mode or Swiped
Everything is working good but there's caution message in ConsoleLog EveryTime
As I know, there're some Messages I can ignore But I want to know if it's Okay to ignore it
Is it okay to put bigger width for item than collectionView width and ignore that Message?
I don't want you to waste your time with reading every Single line of my code and fix for me
So, I just hope to hear your Idea and if there're some points I should be careful when I using this Way :)
2020-11-01 19:08:14.917103+0900 IssueTracker[27304:7532603] The behavior of the UICollectionViewFlowLayout is not defined because:
2020-11-01 19:08:14.917210+0900 IssueTracker[27304:7532603] the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
2020-11-01 19:08:14.917241+0900 IssueTracker[27304:7532603] Please check the values returned by the delegate.
2020-11-01 19:08:14.917601+0900 IssueTracker[27304:7532603] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x10571ae80>, and it is attached to <UICollectionView: 0x10a811800;
frame = (0 172; 414 515); clipsToBounds = YES;
autoresize = RM+BM;
gestureRecognizers = <NSArray: 0x2829d5290>;
layer = <CALayer: 0x282780ea0>;
contentOffset: {0, 0};
contentSize: {414, 101};
adjustedContentInset: {0, 0, 0, 0};
layout: <UICollectionViewFlowLayout: 0x10571ae80>;
dataSource: <IssueTracker.IssueListCollectionViewAdapter: 0x28279a2c0>>.
I think that the best way to implement it is by disabling buttons and animating their appearance by changing alpha of text colors. I implemented it this way in my video application and it works perfectly!

Full-screen UICollectionViewCell issue on iPhone X in landscape

In my app, I present a view controller modally, and this view controller contains a UICollectionView that fills the superview. Each cell in the collection view needs to be full-screen - the same size as the view's bounds. To accomplish this, I simply set the itemSize of the UICollectionViewFlowLayout to be the view's bound's size in viewDidLayoutSubviews.
This works really well on all devices and orientations, except iPhone X in landscape. When presenting that screen in that case, it seems the safe area layout margins are coming into play and affecting positioning of the cell. The cell is pushed over from the left edge of the display, and pushed up such that the bottom of the cell is aligned to the vertical center of the home indicator. Inspecting the layout with View Debugger reveals the collection view fills the screen, but the cell's Y position is -10.67 and the X position is 0, even though it is inset from the leading of the collection view. Notably, this is logged in the console:
The behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7fa6311253b0>, and it is attached to <UICollectionView: 0x7fa63207e800; frame = (0 0; 812 375); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x608000244d70>; layer = <CALayer: 0x60800023ef00>; contentOffset: {-44, 0}; contentSize: {0, 812}; adjustedContentInset: {0, 44, 21, 44}> collection view layout: <UICollectionViewFlowLayout: 0x7fa6311253b0>.
What's going on here and how can this be resolved?
By default, iOS 11 automatically adjusts content insets for iPhone X in landscape, causing this issue to occur. To resolve it, you can simply disable the automatic content inset adjustment, as it's not needed nor desired in this scenario.
collectionView.contentInsetAdjustmentBehavior = .never

How to enable touch events on tableHeaderView while the UITableView is still scrolling?

I've created a UITableViewController in my storyboard, and added a UIView as a tableHeaderView. I have an MKMapView in the tableHeaderView, but my problem is that the map in the tableHeaderView doesn't receive touches before the tableView completely stops scrolling. Rather if a touch occurs before the scroll ends decelerating, the scroll continues, and this is unwanted behaviour.
I've already tried subclassing the UITableView to override hitTest, but can't figure out what to return as the output of events within the tableHeaderView are as follows:
<MKNewAnnotationContainerView: 0x1589ac3a0; frame = (0 0; 375 310.5); autoresize = W+H; autoresizesSubviews = NO; layer = <CALayer: 0x170c3c5e0>>
So, is there a way to interact with the tableHeaderView simultaneously when the scrollView is decelerating?
It seems TableHeaderViews are not really made for things like this. You should simply add the MKMapView at the top of the UITableView, this will solve your problem.

UISplitViewController's different layout behaviour for Custom Cells in Master Controller

An UISplitViewContller's the master view controller (TAbleView) has 2 types of cell prototypes.The iOS's default one is working fine but my custom cell has layout problems so all the subviews are missing.
If I present the master view controller modally all the subviews in the cell are laid out correctly.That means it is not related with the constraints set inside the content view of the cell.
Is there something special that i need to care about?
Second cell's subview are missing.
How they should look like.
Edit:
If i debug the layoutSubviews, i see that coordinates of the labels are not right.
<UILabel: 0x7fa8f0de82f0; frame = (0 -21; 42 21); text = 'Subtitle';
opaque = NO; autoresize = RM+BM;
userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fa8f0de84a0>>
Constraints for the Subtitle Label
After playing around with constraints I figured out that the problem was related with the size classes.
You need to specify the constraints for Splitview's master in ANYxANY size class not anything else.Mine were added in Regular to Any.

UIButton in scrollView unresponsive when outside initial frame

I have a very long view (>2000 pixels) created in a xib. This xib is loaded and then, inside it's ViewController I switch the root view for a scroll view (I want that 2000 pixels to scroll);
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *view = self.view;
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.frame];
scroll.contentSize = self.view.bounds.size;
self.view = scroll;
[scroll addSubview:view];
}
The long view has a button but it does not fire if it's placed outside the top of the long view (i.e. outside the initial screen frame).
This post seems similar but is slightly different as that SO user is extending the size of the scroll view dynamically. In this case, the scroll view of fixed size (full screen) but I can't hit things in my xib that are outside of the initial frame. During debug, I can see the frame of both the scroll view and content view are set (and long)...
<UIView: 0x946db50; frame = (0 0; 320 2320); autoresize = W+H; layer = <CALayer: 0x946db20>>
<UIScrollView: 0x9077e10; frame = (0 0; 320 2320); clipsToBounds = YES; gestureRecognizers = <NSArray: 0xb388bd0>; layer = <CALayer: 0x9276f60>; contentOffset: {0, 0}>
How can I ensure that taps are making it to controls scrolled into view?
Through trial and error I fixed this, but I'm not sure why it works. In the code above, I init the UIScrollView to have the same size frame as the content view (which actually doesn't make sense, not sure why it scrolls at all).
Instead, I got it working to sizing to the screen (since it will be full screen):
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
And now it all works swimmingly. Odd; would love to understand why this is.
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
this will create a scrollView to the match the actual view of view Controller then
UIView *newView=[[UIView alloc] initWithFrame:CGRectMake(0,0,320,2320)];
[scrollView addSubview:newView];
//u can also create this view from your long view in story board, never use the self.view inside scroll this make Ur hierarchy critical add on more long view inside the controller then refer that view to new instance in view-controller then use here
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, newview.frame.size.height);
then set
OLD answer
Set contentsize property of ur scroll view to macth the height of ur scroll view and width of your view inside scroll view...

Resources