UIScrollView scroll enabling - ios

I'm currently working on a Swift app that requires a few UIScrollViews, however I'm running into some problems making it work for all device sizes.
In this situation, I would have a content that would all appear on an iPhone 6, but not necessarily on an iPhone 4 or 5.
I've got a scroll view set up with some content and I would like to make it scrollable only if you don't see the full content.
Is there a way to perhaps detect if a certain element is visible?

the property scrollView.isScrollEnabled = true by default, and if the content is bigger than screen the user will be able to scroll.

Related

Change UISplitViewController displayMode property when entering multitasking? (iOS 14)

How can I detect when iPad multitasking (i.e. another app brought on screen, side-by-side with my app) becomes active?
I have a UISplitViewController with the following parameters set up as below:
preferredDisplayMode = .twoBesideSecondary
preferredSplitBehavior = .tile
setViewController(SidebarVC(), for: .primary)
setViewController(SuppVC(), for: .supplementary)
setViewController(SecondaryVC(), for: .secondary)
In landscape orientation, there is plenty of room for all 3 columns (.primary, .supplementary, .secondary). In portrait or when multitasking, the screen width is narrower and my 3rd column (.secondary) gets squished to a very narrow width. The horizontal size class remains regular so I can't use that to detect it. (When horizontal size class becomes compact, my UISplitViewController.compact shows and works just fine).
I'm wanting to change the UISplitViewController.displayMode property to .twoDisplaceSecondary when the screen is narrower, but the horizontal size class remains regular (i.e. when in portrait, or when another app is in multitasking). This would allow the 3rd column to be pushed off-screen (displaced) rather than squished.
A perfect example of the exact behavior I'm looking for is the Contacts app on iPad in iOS 14. It uses a triple column layout, seemingly with a displayMode of .tile. When the app is full screen in landscape, all 3 columns are displayed and there is enough room for no squishing to occur. However, if you bring another app into multitasking (thus making the Contacts app width narrower, but horizontal size class remains regular), the displayMode seems to change to .twoDisplaceSecondary, and the 3rd column is pushed off-screen rather than being squished.
I think I can manage orientation changes via viewWillTransitionToSize() method, but I haven't been able to find a delegate or other way to detect when the app is narrower, but still with a .regular horizontal size class, like the Contacts app, is seemingly able to do.
Screenshots to show what I'm referencing:
You can see that in the second screenshot, the 3rd column is displaced rather than squished when there isn't enough space.
I figured out that it's important to set BOTH .preferredDisplayMode and .preferredSplitBehavior when the view transitions. Setting just one or the other will result in lots of weird behavior.
For future readers, what I figured out works for this case is setting preferredDisplayMode = .twoBesideSecondary and preferredSplitBehavior = .tile when the screen is wide enough, then set preferredDisplayMode = .oneBesideSecondary and preferredSplitBehavior = .displace when the screen is narrow. I used a function that checks if the view.frame.size.width < 1194 to determine if the screen is full width or not, as using orientation only would cause problems if the app is side by side with another. I call this in viewDidLoad as well as viewWillTransition(toSize:).
viewWillTransitionToSize has a size param containing the width. Usually you would check for a width less than 1024.

Can't scroll in my iOS application

I'm pretty new in creating iOS applications and currently I'm following Apple's starter tutorial.
They suggest simulating on iPhone 6 which has a pretty big screen and therefore all the content fit its screen, however I'm simulating on iPhone 4 which has a smaller screen. All the content don't fit and I can't see all of the placeholder image. I'd expect that I would automatically be able to scroll so I'm able to view all the content but no.
It seems that you have designed your contents on normal view. Instead you have to use UIScrollView which will allow you to scroll to see all your contents. contentSize property is important for this.
Refer Here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScrollView_Class/
The UIScrollView class provides support for displaying content that is
larger than the size of the application’s window. It enables users to
scroll within that content by making swiping gestures, and to zoom in
and back from portions of the content by making pinching gestures.

Problems Setting up constraints in IOS8 with Swift and Xcode 6

I have tried for several hours to design and place the different elements accordingly. But it seems like no matter what I do, the elements get messed up with sizes and location when moving to different device (screen sizes).
How would you place constraints in the screen below to ensure proper scaling and position when moving to a different device?
http://postimg.org/image/hl4incjzh/
I only work in portait mode.
The views at the left is a UIImage view and a UIWebview which is hidden, and will show dynamically based on external content.
Label and the textview below is also dynamically populated on ViewDidLoad.
Any ideas, suggestions?
You can click on a view element and use the add-constraints-menu:
There you can set different size-options like the margin, if the view should resize etc.

iOS app only showing half in simulator

I am trying to develop a simple app with one screen for iOS and am running into a strange problem. Only half of the app is showing up. For example I have a screen with just one button in the center of the screen. When I run the app in the simulator I only see half the button and I cannot move it either.I can scroll the view in the simulator vertically but not horizontally. I am stumped. Will appreciate any pointers.
I'm pretty sure you built your view using the main storyboard and put everything in the middle of it. The main storyboard is set to take all iOS format into account, iPhone and iPad. If you want your app to appear centered on your iOS device, you need to constraint the position of your different UI objects, using Auto Layout. That way it would appear centered automatically, whatever is the device you're using
I reckon you've got AutoLayout turned on... but haven't set any constraints on your controls yet.
Try the following test:
Go into your Storyboard file.
Click on a blank area in your storyboard, then on your screen (so the border of your screen is blue - not black or gray).
In the menu bar, click on Editor \ Resolve Auto Layout Issues, and then "Update Frames".
Alternatively, you can click on the following button, and select "Update Frames" from there (it doesn't matter which one):
When you do this, where does your "one button" end up ? Does it suddenly disappear off the screen, have a negative X or Y position, or a width/height of 0 ? If so, then AutoLayout is your problem.
With XCode 6.1, Apple has put a gun to developers' heads and demanded that when you add an object to a Storyboard, you must - straightaway - add some constraints to it.
I had this issue when I first upgraded to XCode 6.
I would add, say, a View to a screen, stretch it to a particular size, then drag a second control (perhaps a Label) onto the same screen. Suddenly, my View would resize itself to a height/width of zero, or be positioned way off the side of the screen... huh ?!
To get around this, when you add a control onto a Storyboard, you must add sufficient constraints to really let XCode calculate where to position it, based on which device/orientation the device is running on. And, yes, you sometimes need to do this straightaway before XCode ridiculously decides to mess up your control's position or size.
I really do loathe XCode. This isn't the way a development environment should behave in 2015...
If I get your point of problem then
I m sure the problem is you have auto layout and size classes enabled.
check if you have Auto layout and size classes enabled ....???
If yes then you haven't set the constraints accurately. set the constraints for the UI Objects to show on your desired position in screen.

iOS8 When using VoiceOver content of the collection view is scrolled to beginning

I have simple collection view created programmatically with build in horizontal layout and 50 items. When I enable VoiceOver to speak content of each cell, scroll position is changed to beginning on first item.
I would like to preserve scroll position. Am I missing something when VoiceOver is enabled?
With voice over disabled it works without issues.
Good to mention it works without issues on iOS7. I am using xcode 6.

Resources