Create onboard screen in swift - ios

I have created onboard viewcontroller using UICollectionView
but when I swipe, the picture goes out of the iphone, I want the picture to clip inside the phone and show other image. How can i achieve that?

Make the frame of the collection view fit the the screen of the phone image.
For example if the upper left corner of the screen of your phone image is located at x:20, y: 40 and the screen of your phone image is 160x300 big, then the following should be your collection views frame:
collectionView.frame = CGRect(x: 20, y: 40, width: 160, height: 300)
If you are using AutoLayout, make sure that the edges of your collection view are lined up with the edges of your phone images screen.

Related

Incorrect height of an uiview

I'm trying to put an uiview over the main view controller. The way i'm doing it, looks like this (the red view is the view, and the black one is the main view controller)
But i want it to look like this...
This is the code i have tried (the "viewww" is the red view)
viewww = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height - navBar.frame.height))
What i want is to have a space in the top (the height of a navbar) and not in the bottom when the "viewww" appears, but i don't know how to set the space in the top.
Thanks in advance!!!
This puts your view down to the height of the navBar
viewww = UIView(frame: CGRect(x: 0, y: navBar.frame.height, width: self.view.frame.width, height: self.view.frame.height - navBar.frame.height))
The cleanest way to do this, without hard-coding navigation bar heights, is to use autolayout. Constrain the view's leading and trailing edges to the superview's, and constrain the view's top and bottom edges to the top layout guide and bottom layout guide (or, if you're using iOS 11, the Safe Area edges). See https://useyourloaf.com/blog/safe-area-layout-guide/ for a fuller explanation.

Buttons at Bottom of Scrollview Don't Respond

I have a UIScrollView with several buttons in it. The buttons at the bottom of the scrollview are visible, but don't respond when they're pressed. My problem appears to be the same as the one in this Stackoverflow Question, but the accepted answer does not seem to solve my problem; the frame of the scrollview, the contentSize of the scrollview, and the frame of the view inside the scrollview (which is also the superview of the problematic buttons) all have width 414pt and height 900pt. That should definitely be large enough to encompass the buttons which aren't responding.
EDIT:
I created the scrollview in Interface Builder. The edges of the the container view within the scrollview are pinned to the edged of the scrollview.
I tried adding these lines of code:
scrolling.frame = CGRect(x: 0, y: 0, width: 414, height: 900)
viewInsideScrollview.frame = CGRect(x: 0, y: 0, width: 414, height: 900)
scrolling.contentSize = CGSizeMake(414, 900)
self.view.frame = CGRect(x: 0, y: 0, width: 414, height: 900)
Adding these lines didn't change how the scrollview looked or acted (scrolling fine, but with unresponsive buttons on the bottom.)
A UIScrollView infers its size by the view/views inside of it. You created your views in the interface builder so that could be why the lines of code you added did not work (I am not entirely sure why they did not). However, what will work is setting constraints on your viewInsideScrollview so that the scrolling expands to the full content size. For example, if you have 10 buttons in your viewInsideScrollview, you should set a top space constraint on the top most button, leading and trailing constraints, constraints to give spacing in between buttons, and a bottom space constraint on the bottom most button. The scrolling will expand to accommodate all of the buttons, and you will be able to select all of them.

Lock UIView position relatively to UIScrollView

I am trying to create an interface that shows a floor plan with markers in fixed positions so when user zooms or scrolls the floor plan, markers stay on the same position relative to floor plan image.
So far I tried to do it with a UIScrollView that holds an UIImageView and then I tried to add some dummy subview
let view = UIView(frame: CGRect(origin: CGPoint(x: 400, y: 200), size: CGSize(width: 36, height: 36)))
view.backgroundColor = UIColor.redColor()
scrollView.addSubview(view)
but origin (in my example 400,200) is relative to screen, which means that the dummy subview shows only when you zoom enough and then slides along if you scroll around.
I can't figure out how to fix this. Maybe I should use some other UIKit classes?
Try that
create a container view of the preferred size
add the image view as a subview of this container view
add you dummy subview in the container view
from the zoom delegate method of the school view return the container view
The fact is that they need a common ancestor view

How to make a view with picker and toolbar stay at the bottom of iphone screen

I am using this code and its placing my view at the top of the viewing area instead of the bottom. Any idea what I am doing wrong? I am not creating the view in swift because I already have it created in IB with a toolbar and pickerview inside it.
let height = view.frame.size.height
yearView.frame = CGRect(x: 0, y: height - 250, width: self.view.frame.width, height: 250)
Even if I use the y coordinate and say 50 the view wont budge from the top. All I am trying to do is place this subview at the bottom of any sized phone's screen so they can select a value inside the view.
yearView.frame = CGRect(x: 0, y: height - 250, width: self.view.frame.width, height: 250)
Try moving it out of the ViewDidLoad, you need to position that view whenever you unhide it, otherwise it will not show.

UIPresentationController - presentation view size?

I'm using a UIPresentationController, but I can't sort out how to get it showing the way I want it to.
I'm editing the frameOfPresentedViewInContainerView() function, and I need to be returning the frame (a CGRect) to display my content in.
The tutorial I followed uses CGRectInsert(self.containerView.bounds, 50, 50), which makes the window centered with the borders brought in 50px. If I return self.containerView.bounds just as itself, the view takes up the whole screen.
I'd like the overlaying view to be the width of the parent view (so, self.containerView.bounds.width), but I want the height to be the size needed to show the content of the new view without cutting anything off.
I tried a CGRect at (0,0) with width and height from self.preferredContentSize, but it's not returning sizes that work.. What can I do?
I tried frame = CGRect(x:0, y: self.containerView.bounds.height/2, width: self.containerView.bounds.width, height: self.containerView.bounds.height/2) just as a test (but that's just making the view half the size of the parent view), but when I rotate the screen, suddenly the new view is almost off screen..
Aside from frameOfPresentedViewInContainerView(), I also had to add the following to make it work.
- (void)containerViewWillLayoutSubviews
{
self.presentedView.frame = [self frameOfPresentedViewInContainerView];
}

Resources