IOS: How to send an Image View back and front - ios

In my storyboard I have a view on which I have an ImageView and a Button. The ImageView is currently covering my button and I would like to put the button over the ImageView. I found similar topics which were solved by going to "Editor" -> "Arrange" -> "Send to Front", however that was done for UIViews and this option is passive for ImageView and Buttons.
So how can I send my ImageView to background? Is the best solution for this to add an additional view only for the Button and then bring it to front?

You can rearrange your views on storyboard:
First view in order will be hidden by next view.
Maybe this options will be also useful for your running application:
myImageView.layer.zPosition = -5;
myImageView.layer.zPosition = 5;
Like in HTML/CSS.

The solution was to move the view components up and down in the "Document Outline" section.

Alternatively, you could've solved the problem using the bringSubviewToFront function:
[self.view bringSubviewToFront:self.yourButtonControl];

Related

iOS : adding zposition and button action doesn't work anymore

Hi I have implement a walkthroughs in beginning of my app and a button in last walkthroughs view for going to another view controller but I didn't see the button so I searched and add this statement
self.mybutton.layer.zposition = 1
so finally after this code I see my button but the action for my doesn't work anymore ??
thanks for any help
Move your button to on top of all other views in story board and then check
UIApplication.shared.keyWindow!.bringSubview(toFront: yourBtn)
Use bringSubviewToFront instead of zposition
[self.view bringSubviewToFront:self.mybutton];

swipe navigation in objective-c

I want to add a second view controller to my project with a swipe navigation. Which is the easiest way?
As you can see in the picture I have these buttons in the first view, I want to add more. I also have a background picture which is not in the picture
(below), is it possible to keep it for both views? So when I swipe to the right the background should't move, only the buttons.
Also could you please explain to me how I should make it step by step, because I am new into coding and have almost no experience.
I think what you are trying to find is paging using UIScrollView. Check out this link.
Hope this helps you.
you can use the custom class called ADPageControl. Here is the reference link : https://www.cocoacontrols.com/controls/adcustompagecontrol.
And for that image you can set the common image below your container view. Please go through the link and try to implement it.
Basically you need a UIPageViewController But you have tweak a little bit. You can find a tutorial about that here
Few Points
Create PageViewController with buttons
Make each Page views background color as clear color so your background image will be shown all the time even when you swipe.
Please don't expect full code from SO
I think you trying implement something like ..look below code
its scrollview paging
// viewArray contains paging views
viewArray = [[NSMutableArray alloc] initWithObjects:self.viewOne, self.viewTwo, nil];
// adding all views as scrollview subview
for (int i = 0; i < viewArray.count; i++) {
self.scrollView.pagingEnabled = YES;
[self.scrollView addSubview:viewArray[i]];
}
// this time you need to set scrollview contentSize but in X axis ..
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * viewArray.count, self.scrollView.frame.size.height);
have a note: you can create views using storyboard or programmatically but must set the x position of views which you want to appear on swipe.. hope this helps.

How to make the buttons visible on simulator?

I'm using Xcode 5.1.1. I recently added a background image to my application but the buttons on the view controller aren't visible. When I remove the background image, the buttons become visible again. How to handle this?
If you are not checking the view hierarchy, then do one thing create outlet of you button and then write following code in viewDidLoad.
[self.view bringSubviewToFront:yourButton];
I don't know if you were used xib...
If you are using xib in your project, giving a background image for your button will more easy.
Place a button anywhere you want. Then go to attributes inspector on the right hand side. There you can find a field for changing your background image. Just give the name of your image.
Hope it will helpful for you

Button Responsiveness at UIScrollView

I am dynamically creating a uiscrollview and i place some uiview's that contains some label and buttons inside to display some news. Every button inside the sub uiview calls a rest function to like, unlike or share the news. Some of the buttons opens overlay screens like comment news. I am assigning actions to buttons inside the main form that contains the uiscrollview.
When i click a button that opens an overlay screen. When i close the overlay screen and hit Like button, it does not respond to touches. After attempting one or two more times, it works.
Does anyone has any idea about this issue?
Are you using UITapGestureRecogniser for "Click action"? If yes, you propably want to set flag "cancelsTouchesInView = NO" for this recogniser.
Check to see if there is a clear view covering your button. That view will consume your tap, so the button never sees it.

Bring UIButton to front layer

I know there is a way of bringing a subview to the front of the hierarchy. However is there a way of bringing a button that i have placed on a story and calling a function that will make that button the top layer so its not hidden by any other elements that are added that aren't in the story board.
Thanks,
I am late for this question, but not too late to answer it by Swift 3
Swift 3
view.bringSubview(toFront: theButton)
A UIButton is a UIView, so you can call -bringSubviewToFront: on your button instance.
uiview's are displayed in the order they are stacked. One can change this to say were to insert the new uiview, which in your case is a uibutton.
One way of doing that is by creating a IBOUtlet of the uibutton and adding that button instance as a subview/newview above an existing uiview.
CODE:
[self.view insertSubview:<new Uiview> aboveSubview:<existing uiview>];
Also if you are not able to figure out the order of the uiview , then you can check that in xcode
When running the project in debug mode under debug window there is a button(highlighted in below image) Debug View Hierarchy, you need to click that. (highlighted in below image)
After that you will able to see all the views rendering on the screen at current instance, using this feature you will be able to understand were is your new uiview in the uiview stack order(shown below).
Swift
The following works great if the view you are working with is being hidden views that are in the same view.
superview?.bringSubviewToFront(self)
Swift 5
In my case I had to insert my view behind some buttons. By insert it at the zero position it was placed behind the buttons.
self.view.insertSubview(self.mapView!, at: 0)
i have the same problem with you and a friend of mine helped me
i can bring my button to another subview using this function on your view controller where you declare your button.
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.keyWindow?.addSubview(chatButton)
}
button.superview?.bringSubviewToFront(button)

Resources