I'm creating UIView programmatically and called this UIView captureImage. This UIView captureImage display the image that I capture from camera and the parentView I called it self.frameForCapture. But the problem is, It always overlap the UIView that I add to the storyboard.
Update Post:
Here is the image that I'm trying to make in my app.
Black View is my parentView and I called it self.frameForCapture.
Blue View is childView, and I add it using the storyboard.
Red View is childView, and I programmatically added to the parentView.
But the time I add it the redView. It always overlap the blueView, i use this addSubView:.
But if I used these
[self.frameForCapture bringSubviewToFront:captureImage];
[self.frameForCapture sendSubviewToBack:captureImage];
nothing happen.
I used this code:
self.newalbumImageView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.newalbumImageView setContentMode:UIViewContentModeScaleAspectFill];
self.newalbumImageView.image = self.albumImage;
UIView * captureImage = [[UIView alloc] initWithFrame:self.frameForCapture.frame];
[captureImage addSubview:self.newalbumImageView];
[self.frameForCapture addSubview:captureImage];
there are a few things that can help you look at this question How to make a UIView always appear at the front?
just link the headerview to .h file and use myAlwaysOnTopView.layer.zPosition = MAXFLOAT;
another thing is that when you use [self.frameForCapture sendSubviewToBack:captureImage];
the redview will still be on top of self.frameForCapture if don't want it like that you can hide it or even remove
if you still have this problem just tag me
Related
I want to add a "shadow" image on my view, but, i want part of my view to still be "visible". You better understand what i want to do, when look on screenshot:
I can add a UIView above my superview, but how could i make specific point "visible"? That actually mean make specific area of a view with different colour or opaque.
For your problem I had a way, try the below example.
1. First storyboard design: I had a UIButton
2. Added black View as a subview
UIView *blackView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
blackView.backgroundColor=[UIColor blackColor];
blackView.alpha=0.6f;
[self.view addSubview:blackView];
now result will be:
3. Add one more UIImageView with frame equal to button frame
UIImageView *imageView=[[UIImageView alloc]init];
imageView.frame=self.button.frame; //getting current UIButton bounds
imageView.image=[UIImage imageNamed:#"add_img.png"];
[self.view addSubview:imageView];
Now it looks same as what you want:
You have to add some views. A main view will be the container of your less-alpha view and of the opaque button.
MainView
|
------- UIView with 0.6 alpha
|
------- UIButton with 1 alpha
Indeed, if you change the alpha of the MainView, all subviews will be affected. Here, UIView with 0.6 will have the same frame as MainView but it will not affect UIButton alpha.
Make a new View, a parent View with clear color background. Add the black view and the button to the parent view and set the black view's alpha to 0.6 or whatever.
Try this:
Make a UIView called buttonBackgroundView, give it a black color and then
[self.view addsubView:buttonBackgroundView];
now make a UIView named plusView (or UIButton if this plus sign is a button) then
[self.view addsubView:plusView];
After that, give the alpha to the buttonBackgroundView
buttonBackgroundView.alpha = 0.6;
Happy coding!
I have a storyboard with a square imageView in the middle at: 280,140 (vertical)
When the application starts i am able to move this imageView by pressing buttons. I move the imageView using:
_mainImage.frame = CGRectMake(_mainImage.frame.origin.x + 2, _mainImage.frame.origin.y, _mainImage.frame.size.width, _mainImage.frame.size.height);
while the application is running i keep adding new imageViews to the mainView:
UIImageView *imgView;
imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, yCoordinate, 50, 10)];
imgView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:imgView];
each time i call this code the square imageView i have placed in the middle and moved around, gets set back to its starting position. It seems like the mainView gets "reset" each time the addSubview gets called. Is there any way i can add a subview without having the mainView "reset"?
Most likely your view is set up using Autolayout (this is the default for storyboards or nibs) and when you add a new subview, a layout pass is performed which resets your views position back to that defined by its original constraints.
You should move your view by updating its constraints, or turn off Autolayout. There are lots of posts around explaining how to do either of these things.
I'm trying to make a square (50 x 50) UIView in the lower right hand of my main view, but I'm confused about why it's not entirely visible. In this instance, only the tip of it is visible from the bottom. Am I confusing some concept?
CGFloat width = CGRectGetWidth(self.view.bounds);
CGFloat height = CGRectGetHeight(self.view.bounds);
UIView *transparentFloater = [[UIView alloc] initWithFrame:CGRectMake(width - 50.f, height - 50.0f, 50.0f, 50.0f)];
[self.view addSubview:transparentFloater];
Try to add the autoresizing mask:
transparentFloater.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
If I am not wrong, You have created your ViewController with xib and in the attributes of view, you have forgot to mention that you are using a "navigation bar" as "top bar".
Reason
So in ViewDidLoad, view in .xib with a height X is returned. But as you might have loaded the viewController using UINavigationController, after loading the height of view is decreased by 44pixels.
Suggestions :
1) Whenever you know that you are going to have navigation bar on top please mention it in .xib file as well.
For doing so click on the view in xib and select the option called topbar in attributes Inspector of utilities area
2) Call the following api
NSLog(#"In ViewDidAppear %#",NSStringFromCGRect(self.view.bounds));
in
viewDidLoad
viewDidAppear
to track whats happening with the bounds of view
You does not need to do anything just put
transparentFloater.backgroundColor = [UIColor redColor];
because your view (custom) is invisible (because your main view color and custom view color are same (white) ) may be. I tried your code in my demo project. it worked perfectly for me.
How do I change the order of views displayed, when the two views I want to rearrange are not related?
I am trying to work on someone else's code, and they have a class which is a subclass of UITableViewController. I want to put a background in, so I put it as a subview of self.view .
The problem is, it's displayed in front of the table, and the table is located as self.tableView, not self.view.tableView . Since the two views aren't together, I can't use the sendSubviewToBack method.
self is the viewController class I'm working on.
Any ideas?
UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"editInfoBG.png"]];
background.frame = CGRectMake(0, 0, 320, 416);
[self.view addSubview:background];
// Doesn't work, the table is not a subview of self.view
[self.view sendSubviewToBack:background];
If you want to add subviews into your viewcontroller, you should use a subclass of UIViewController with manually added UITableView as subview and implementing the UITableViewDataSource and UITableViewDelegate protocols instead of using UITableViewController.
you can insert the background before the tabeview like this
[self.view insertSubview:background belowSubview:self.tableView.view];
I want to be able to draw custom shapes and so forth on top of a playing movie file. At the moment I have a UIView subclass that I have overwritten the drawRect method in and I do my drawing in here, this works as expected.
I added a MPMovieplayerViewController to my viewController and can play a video on it ok except that I'm guessing that its in a new window on top of my subclassed UIView.
I have tried adding a new UIView as a subview to the movie view.
UIView *newSubView = [[UIView alloc] initWithFrame: CGRectMake ( 0, 0, 100, 100)];
newSubView.backgroundColor = [UIColor redColor];
[theMovie.view addSubview:newSubView];
And I can see this works because I can see the red View on top of my video, but how can I add a subview with a drawRect method that I can draw in?
I have spent way too long on this and now hope a noble coder is able to point me the right direction.