I have a grid of views, which are being added as subviews to a main view. When I drag a view which was added prior to the next one, and try to drag it underlays the view rather than overlay that view. How can I fix that content while the view are being dragged on touchesMoved?
[self.view bringSubviewToFront:yourView];
Hope this helps...
There is also another way, You can import
#import <QuartzCore/QuartzCore.h>
and each of view set zPosition like this
view.layer.zPosition = z;
Related
I have a UIView with labels and textfields and I tested it in the simulator and noticed that I cannot scroll to see the rest of the view, how can I make the view into a UIScrollView and what do I need to do so I can make the view scrollable? I don't want to move labels and stuff or delete the UIView, is there a simple way?
Take a UIScrollView in Xib file outside your view. drag your view into this scrollview. The subviews inside your view remains same. and set the scrollview's contentSize
I have built a small iOS 6 app that uses a single view. However, I would like to add some more functionality and therefore need more space. I figured that the best way to do this is to add a UIScrollView.
How can I add such a UIScrollView to my View? Do I have to delete all my buttons, labels, etc. in my View, then add a UIScrollView and then put all those buttons, labels, etc. in that UIScrollView? I think that this would work but is there an easier way to do this? (Maybe without deleting all the content in my view)
Yes you can add a view to UIScrollView without deleting buttons, labels, etc..
To add a scroll view to existing view:
Draw and drop the UIScroll View to the existing View
Select all controls in the View like Buttons, Label etc.; except UIScroll View
Drag all the selected component into UIScroll View
Let me know if you have any doubt.
Add all views on scroll view like:
[scrollview addSubView:button];
And finally add this scrollview to main view:
[self.view addSubView:scrollview];
I think this will be helpfull. :)
programmatically you have to
[scrollview addSubView:button];
instead of [self.view addSubView:button];
In storyboard or xib you can drag and drop the button onto the scrollview.
Hope this helps a little bit.
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)
I want to overlap view over the another view. I don't want to add it as a subView. The new view should be added with following rect size (280,400) on the super view of size (320,460).
Can any one suggest me the right way for doing this.
Thanks in advance
You can do this by use of UIAnimations, replacing one view with the other.
You could add both view as subviews of a superview. And the superviews view controller handles the show and hide of the subviews.
Im not completely sure what you mean, but i will try...
Overlapping == Changing "z-index"
You can use the following to bring your view above the other views it shares its hierarchy with.
[yourview.superview bringSubviewToFront:yourview];
Overlapping == adding to the superview
Then this should do the trick.
UIView *yourview = ???
yourview.frame = CGRectMake(?,?,280,400);
[self.view.superview addSubview:yourview];
Any UIView or variation thereof can respond to the .superview. Its a global "where the heck am I ?"
If you want to go all the way to the uppermost layer, there is also :
[self.view.screen addSubview:yourview];
You can't get much higher than that ;]
I need a UIScrollview to show some static content in my app. I have taken a UIScrollView through XIB and started adding some UIImageViews and textViews in to it. But after coming to the end of the scrollView the view is not exapanding anymore. I need more space so that I can add some more views below. Is there any way in which I can do this (through XIB and not through code).
I struggled a lot to get this done in a more elegant way then the solution described by Csabi.
It's really simple:
In your xib file just add a generic view which is not a subview of your viewController.view (i.e although this view is in your xib file, it is not a part of your viewController's view hierarchy.)
Then select this view and using size inspector set the width and height that suits your need. Add whatever objects you want to this view. Hook up this view to your viewController with an IBOutlet. (Let's call it IBOutlet UIView *myBigView).
in your viewController.view drag a ScrollView and adjust the size of the scroll view as you like. Hook this up to your viewController. (IBOutlet UIScrollView *scrollView)
Now it's super simple:
-(void) viewDidLoad{
[super viewDidLoad];
self.scrollView.contentSize = self.myBigView.bounds.size;
[self.scrollView addSubview:self.myBigView];
}
Yes it is you can define the height of the UIScrollView simply for example height:1800
now you get bigger UIScrollView then your view you can put your objects to scrollview, and if it is filled simply pull it upward and drag and drop other items when you are finished simply pull the scroll view to its position and you have it.
It is simple :)
Hope it helps
Ask if you have any other question