Fix UIButton on top of UIScrollView - iphone

I'm trying to figure out how to overlay a UIButton on top of a UIScrollView. Basically the user would be able to use the scrollview normally. But a button in the top right of the scrollview would remain in a fixed position. Any thoughts?

Don't add the UIButton as a subView of the UIScrollView, but instead of "self.view"

In the InterfaceBuilder there will be a Hierarchal list of items you put in your view, drag the button from being a view belonging to the scrollView to belonging to the view containing the subview.
Your view hierarchy will look like the following
mainView
|
----Button
|
----ScrollView
Instead of
mainView
|
----ScrollView
|
----Button
basically It means both your button and your ScrollView will both be subViews of the exact same mainView. If your scrollView is the mainView put an empty UIView above the scrollView and insert the UIButton & UIScrollView into that

IB is a little finicky when dropping new views directly on the 'fake' interface. What you will need to do is go over to the left in the list of views and select your button view. Now drag it up to below the 'self.view' or whatever is your top level view.
YOu should notice as you raise it up and down in the list that a light blue line will appear. The width corresponds to 'subview' or 'parent' view connection. Play with it a bit to see the difference.
When you feel comfortable, you should be able to place the Button in the 'self.view', not as a subview of the scroll view. Additionally, if you want it to appear on TOP (physical 'Z level') you will need it to be below the scroll view in the list. ( this points out a subtle problem with CStreet's solution)

Related

Making an Expanding Scrollview

I'm currently making a drawing application in Swift, but I wanted the page to be able to expand if the user wanted more room. I figured that I would use a UIScrollView to scroll around the canvas, but I wanted it to expand whenever the user went to the edge of the page, and for the UIImageView that I am drawing on to expand with it. Does anyone know how I would go about doing this?
Thanks!
In storyboard, drag a UIView into your UIScrollView then constrain that view to all sides of the scroll view. Then set the width to whichever value you would like (I would recommend to control drag from your view to the root view of the view controller and select equal widths), then give it a height constraint. Next, you need to connect an IBOutlet to your view controller code for the height constraint you set on the content view inside the scroll view. When you need to extend the page, add to the value of the height constraint and call layoutIfNeeded() on the scroll view.

Create UIButton offscreen with Interface Builder

I want to create a big UIScrollView, its contentView should contain more than 30 UIButton. Positions of these UIButton are not rectiligne and cannot be create 'programmaticaly' so I've placed all these UIButton on a UIView manually. I zoom/dezoom and scroll all over my UIScrollView fine BUT here is my problem : UIButton created offscreen is not accessible, I mean I can't click them (only UIButton created in the CGRect(0.f, 0.f, 320.f, 480.f) can be click.
Any suggestion ?
Create a view, put a scrollView inside that view, and place your buttons on the scrollView. While adding buttons and moving them around, be certain that they're always inside the scrollView by looking at the object hierarchy in interface builder.
You can slide the scrollView around as you place things, no need to zoom. As long as your buttons are children of your scrollView it should work fine.

implement UIScrollview on a particular area of screen?

i am creating an app which has two UIImageViews at top and bottom of the screen and few customs buttons in between them which i am using in a UIScrollview so that user can scroll through them while the two images remain on top & bottom as they are.But when i use the scrollview the buttons scroll over the two UIimageview instead of just scrolling between them or hiding behind them as users scroll down..how can i make the UIImagviews remain on top of the buttons in UIScrollview??
I assume that you use the Interface Builder...
Make sure that:
The frame of the scroll view is between the image view
The Clip subviews of the scroll view is checked
The image views appear after the scroll view in the views hierarchy (if not then you can just drag them inside the hierarchy)

Touchable info (i) button on top of Scroll View

Is there better (framework built in) way to add small "touchable" round info button (i) on top of scroll view? Theoretically I think there should be container view for button(UIControl or UIImageView with png?) and scroll view.
Simply make your information button float above the scroll view by adding it to the scroll view's superview, then ordering the views such that the information button resides on top of the scroll view. You'll retain scrolling capability, while still catching button touches.

Prevent subview from scrolling in a UIScrollView

I have a UIScrollView subclass with a certain subview I'd like to prevent from scrolling (while all the other subviews scroll as normal).
The closest example to this I can think of is UITableView's "index strip" on the right side (look in the Contacts app to see an example). I am guessing this is a subview of the table (scrollview) but it does not move as the user scrolls.
I can't seem to make my subview stay put! How can I accomplish this?
The trick is to adjust the frame of the "non-scrollable" subview inside -layoutSubviews.
Add the view that you want not to move as a sibling view of the scroll view on top of the scroll view instead of as a subview.
You can set it's property called userInteractionEnabled to NO