At first, I am facing a strange problem with a UIScrollView with Pagin enable but only on iPhone 4 and iOS 7.
So the idea is that I have a UIScrollView (A) containing a UIView (B) that has subviews (Cs)
It's working perfectly on iPhone 5 screen size, for both iOS 7 and 8.
It's working perfectly on iPhone 4 with iOS 8.
It's not working properly on iPhone 4 iOS 7.x
After hours of logging, here is the problem :
UIScrollView A frame height : 480 <- EDIT : this was sometimes 480, sometimes 568
UIScrollView A content size : 960
UIView B frame height : 960
The first page is displaying properly.
When scrolling down to the second page, UIScrollView A contentOffset is 392, instead of the expected 480, so that there is not way to see the bottom of the second page, and bottom of the first page is still visible at the top of the second page.
So the question is : How does iOS find the page size ?
Any help will be appreciated !
The page size is the size of the scroll view. It sounds like the issue is that the height of the content is not defined correctly. If you are using auto layout you need to make sure that the constraints are set up properly. Otherwise you can set the size of the content programmatically.
Either way checking programatically what the content size of the view is should confirm if this is the issue.
When running in Xcode 6 you can examine the views on the screen more carefully using this button:
found here:
when your code is running and you are on the correct view
I finally get it by removing the UIScrollView bottom constraint and replace it with a height constraint, setting it to the superview height at run time.
It seems that the scroll view paging size is just correctly evaluated, but may scrollview was too big for the screen.
Related
Because I have a scroll view, I have set my View Controller to freeform with a fixed size (since that was what I learnt). I want to have my scroll view such that it starts with the same contentSize and scrollable size (so that initially you can't scroll), then later after buttons are pressed the scrollable height increases so that you can scroll. I had tested all this on the iPhone Xr model simulator, and it was all working well until I tried switching to a different iPhone model (iPhone 7+). When I tested my program with the 7+ (which is shorter in height), the scrollView was initially scrollable (which it wasn't supposed to), and I think it might be because I have set my View Controller to freeform with a fixed size (which fits the iPhone Xr model which is taller), so when I try using a smaller iPhone model, it still has the same bigger length so it initially is scrollable.
What I want to get is have my scrollView go from the top of the screen of the iPhone to about halfway, x above a button I have. What I had initially was:
scrollView.contentSize.height = 404
Which I now know is completely wrong since I was hard coding it, but I don't know how else I can find the height from the top of the iPhone screen to the button. Perhaps its something along the lines of:
scrollView.contentSize.height = button.frame.origin.y - /*y position of top of iPhone screen*/
I also considered that the height of the scrollView might just be the y position of the button, however, because I have a fixed View Controller height, for iPhones with smaller displays, that would make the scrollView much larger than what I want (a size such that you initially can't scroll).
Hopefully this makes sense, thanks.
How to get the screen size:
let screenFrame = UIScreen.main.bounds // returns a CGRect
let screenHeight = screenFrame.height // returns a CGFloat
Edit: If you are trying to go completely using storyboard, try setting required constraints from the scrollView to the view to get it where you want.
The height of the contentView inside the scrollView can then be set equal to the height of the scrollView, but with a low priority.
I think that should work, though it's easier to explain when starting from scratch. Let me know how it goes.
I have designed simple one page design for universal application. so I had faced issue while checking the 4 inch devices its working fine. other than 5.5 to above devices its not looking good.
View(MAINVIEW)
ScrollView
View
Label
..
..
above I have mentioned the structure of the page.below I have mentioned screen shots.
above Screen shots image I have designed. with all constraints.
after that I have checked the preview of the page design.
Iphone 4-inch its showing fine. but Iphone 5.5 its showing in bottom not filled whole page view.
It looks like then you have set the height constraint for ScrollView or view. If you did this then remove that height constant and set the bottom constraint which should have 0 constant value to its superview.
I'm part of a team working on an app that uses auto-layout for the iPhone 6, but we just found out that we also need to support iPhone 4s and 5. Because the layout was designed for 6's larger screen, we decided to use ScrollViews.
I used this video as a tutorial of sorts:
UIScrollView and Autolayout - Xcode 6
For the most part, it works. I can scroll up and down.
The Problem:
Scrolling vertically works. But now I also have to scroll horizontally, which is not ideal / shouldn't happen.
Even with the simulator set back to iPhone 6, anything with the scrollview gets widened to the point that the user has to scroll sideways.
Any suggestions?
What I Tried:
Some parts of the app does work without a hitch as far as my eye can see, but I've yet to apply a scrollview to those, so it's hard to tell if it's the scrollview's fault or something else at work. I did find this, though:
Non-working (scrollviews used - can scroll down, but width gets blown up):
Working (no scrollviews used - can't scroll down, but UI matches screen width):
I have no idea if that actually makes a difference. I tried to set the size to any/any as well, but that screws up with existing auto-layout constraints.
I also tried doing it programatically, but there's some known issues regarding the system returning the wrong screen size (which screws up everything even worse).
When working with ScrollView & AutoLayout you should put all content in a content view(UIView) and pin it to scroll view. (I am assuming this you did)
Now, If you want to disable horizontal scroll(like in TableView) then you will need to add a equal width constraint between scroll view & content view.
I have UIViewController on storyboard.
On the image you can see top gray is simple UIView while bellow is UITableView.
And I set uiview to be 150 height.
I use autolayout.
Problem is that when I run app on iPhone 6 uiview height is about 40% of the UIViewController.
From some reason it's height is larger than 150.
Can somebody explain me how can I setup view so I have UIView always the same size?
I think the problem is with your view height....you can not give static height.... see the images and check out where you missing out....
and the o/p is in 4.7 , 5.5 , and 4 inch is
for all the height of view is looking same....that is of 150 height
Have you included an iPhone 6 launch image? My guess is that the iPhone is resizing up based on the resolution of the 4" screen. Include either a static launch image, or a dynamic, xib-based one, and I think that should fix your problem.
I have a scrollview that is working in iOS8, but not in iOS7. My xib file has the scrollview outside the main view. I add the scrollview to the view with:
helpScrollView.contentSize = helpScrollView.frame.size;
helpScrollView.frame = self.view.frame;
[self.view addSubview:helpScrollView];
I have confirmed by printing the values to the console that the content size after this is 320x670 and the frame size of the window to be 320x568. However, in iOS7, the scrollview won't scroll even though the content is cut off. It will scroll as expected in iOS8. The scrollview contains a multiline label that fills the scrollview. I am getting a warning for "Automatic Preferred Max Layout is not available" so that could be related. Any help would be great!
Joseph
It work for me,
"For some reason, viewDidLoad is too early in the life cycle to obtain the scroll view's adjusted frame on iOS 8, but again it works on iOS 7. viewWillAppear is also too early, as well as viewWillLayoutSubviews.
To solve the problem, I just moved the code where I need to use the scroll view's frame size to viewDidLayoutSubviews which does finally obtain the correct size it will be when it appears."
UIScrollView frame is a different size on iOS 8 vs iOS 7