How to add a view behind other view in iOS
I want to add a view under my tab bar analog in iOS and then show it with animation coming from behind it. But when I use my code, the view that must come from behind my tab bar overlaps my tab bar for a while.
This is my code:
- (void)handlePressedButton
if (pressedButton.selected)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform1 = CGAffineTransformMakeTranslation(-196.0, 0.0);
CGAffineTransform transform2 = CGAffineTransformMakeTranslation(0.0, 0.0);
[leftPanelView setTransform:transform1];
[movedView setTransform:transform2];
[UIView commitAnimations];
pressedButton.selected = NO;
else
pressedButton.selected = YES;
if (leftPanelView)
[leftPanelView removeFromSuperview];
leftPanelView = nil;
CGRect viewFrame = CGRectMake(-196, 0, 236, 748);
leftPanelView = [[UIView alloc] initWithFrame:viewFrame];
leftPanelView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"left-nav-content.png"]];
// Code to populate leftPanelView according to what button is pressed.
[self populateLeftPanelView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view addSubview:leftPanelView];
CGAffineTransform transform1 = CGAffineTransformMakeTranslation(236.0, 0.0);
CGAffineTransform transform2 = CGAffineTransformMakeTranslation(112.0, 0.0);
[leftPanelView setTransform:transform1];
[movedView setTransform:transform2];
[UIView commitAnimations];
Here the leftPanelView is the view that must come under a tab bar. Moved view is another view, that is at the right of left panel (don't mind it)
iphone ios view core-animation
add a comment |
I want to add a view under my tab bar analog in iOS and then show it with animation coming from behind it. But when I use my code, the view that must come from behind my tab bar overlaps my tab bar for a while.
This is my code:
- (void)handlePressedButton
if (pressedButton.selected)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform1 = CGAffineTransformMakeTranslation(-196.0, 0.0);
CGAffineTransform transform2 = CGAffineTransformMakeTranslation(0.0, 0.0);
[leftPanelView setTransform:transform1];
[movedView setTransform:transform2];
[UIView commitAnimations];
pressedButton.selected = NO;
else
pressedButton.selected = YES;
if (leftPanelView)
[leftPanelView removeFromSuperview];
leftPanelView = nil;
CGRect viewFrame = CGRectMake(-196, 0, 236, 748);
leftPanelView = [[UIView alloc] initWithFrame:viewFrame];
leftPanelView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"left-nav-content.png"]];
// Code to populate leftPanelView according to what button is pressed.
[self populateLeftPanelView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view addSubview:leftPanelView];
CGAffineTransform transform1 = CGAffineTransformMakeTranslation(236.0, 0.0);
CGAffineTransform transform2 = CGAffineTransformMakeTranslation(112.0, 0.0);
[leftPanelView setTransform:transform1];
[movedView setTransform:transform2];
[UIView commitAnimations];
Here the leftPanelView is the view that must come under a tab bar. Moved view is another view, that is at the right of left panel (don't mind it)
iphone ios view core-animation
Check if this works : [self.navigationController.view insertSubview: <subview> belowSubview:self.navigationController.navigationBar];
– Jayprakash Dubey
May 6 '16 at 6:20
add a comment |
I want to add a view under my tab bar analog in iOS and then show it with animation coming from behind it. But when I use my code, the view that must come from behind my tab bar overlaps my tab bar for a while.
This is my code:
- (void)handlePressedButton
if (pressedButton.selected)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform1 = CGAffineTransformMakeTranslation(-196.0, 0.0);
CGAffineTransform transform2 = CGAffineTransformMakeTranslation(0.0, 0.0);
[leftPanelView setTransform:transform1];
[movedView setTransform:transform2];
[UIView commitAnimations];
pressedButton.selected = NO;
else
pressedButton.selected = YES;
if (leftPanelView)
[leftPanelView removeFromSuperview];
leftPanelView = nil;
CGRect viewFrame = CGRectMake(-196, 0, 236, 748);
leftPanelView = [[UIView alloc] initWithFrame:viewFrame];
leftPanelView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"left-nav-content.png"]];
// Code to populate leftPanelView according to what button is pressed.
[self populateLeftPanelView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view addSubview:leftPanelView];
CGAffineTransform transform1 = CGAffineTransformMakeTranslation(236.0, 0.0);
CGAffineTransform transform2 = CGAffineTransformMakeTranslation(112.0, 0.0);
[leftPanelView setTransform:transform1];
[movedView setTransform:transform2];
[UIView commitAnimations];
Here the leftPanelView is the view that must come under a tab bar. Moved view is another view, that is at the right of left panel (don't mind it)
iphone ios view core-animation
I want to add a view under my tab bar analog in iOS and then show it with animation coming from behind it. But when I use my code, the view that must come from behind my tab bar overlaps my tab bar for a while.
This is my code:
- (void)handlePressedButton
if (pressedButton.selected)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform1 = CGAffineTransformMakeTranslation(-196.0, 0.0);
CGAffineTransform transform2 = CGAffineTransformMakeTranslation(0.0, 0.0);
[leftPanelView setTransform:transform1];
[movedView setTransform:transform2];
[UIView commitAnimations];
pressedButton.selected = NO;
else
pressedButton.selected = YES;
if (leftPanelView)
[leftPanelView removeFromSuperview];
leftPanelView = nil;
CGRect viewFrame = CGRectMake(-196, 0, 236, 748);
leftPanelView = [[UIView alloc] initWithFrame:viewFrame];
leftPanelView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"left-nav-content.png"]];
// Code to populate leftPanelView according to what button is pressed.
[self populateLeftPanelView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view addSubview:leftPanelView];
CGAffineTransform transform1 = CGAffineTransformMakeTranslation(236.0, 0.0);
CGAffineTransform transform2 = CGAffineTransformMakeTranslation(112.0, 0.0);
[leftPanelView setTransform:transform1];
[movedView setTransform:transform2];
[UIView commitAnimations];
Here the leftPanelView is the view that must come under a tab bar. Moved view is another view, that is at the right of left panel (don't mind it)
iphone ios view core-animation
iphone ios view core-animation
asked Mar 20 '12 at 15:43
wzbozonwzbozon
8,78145860
8,78145860
Check if this works : [self.navigationController.view insertSubview: <subview> belowSubview:self.navigationController.navigationBar];
– Jayprakash Dubey
May 6 '16 at 6:20
add a comment |
Check if this works : [self.navigationController.view insertSubview: <subview> belowSubview:self.navigationController.navigationBar];
– Jayprakash Dubey
May 6 '16 at 6:20
Check if this works : [self.navigationController.view insertSubview: <subview> belowSubview:self.navigationController.navigationBar];
– Jayprakash Dubey
May 6 '16 at 6:20
Check if this works : [self.navigationController.view insertSubview: <subview> belowSubview:self.navigationController.navigationBar];
– Jayprakash Dubey
May 6 '16 at 6:20
add a comment |
5 Answers
5
active
oldest
votes
try sendSubviewToBack
[self.view sendSubviewToBack:leftPanelView];
I accept your answer, coz you've sent it after 2 mins, I posted. I think it's fair.
– wzbozon
Apr 9 '12 at 17:06
10
This does not answer the question asked. All this does is move a view to the back of the subview chain. The answer below from He Shiming is correct.
– Rickster
Apr 7 '15 at 18:03
Thanks for the answer. It worked for me.
– Ramakrishna
Feb 6 '17 at 7:15
add a comment |
Besides addSubview
, there are other methods you can rely on to add your view:
– insertSubview:aboveSubview:
– insertSubview:belowSubview:
– insertSubview:atIndex:
You can control the index (actually z-index, or layer order) of the view using these methods.
1
For meinsertSubview:belowSubview:
solved the problem! Thx
– Alex Cio
Oct 22 '14 at 12:31
1
This should be the right answer. the above answer doesn't answer what was asked.
– MarkosDarkin
Oct 25 '17 at 12:41
add a comment |
Oh, I found a solution myself. I added after this:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view addSubview:leftPanelView];
this line:
[self.view sendSubviewToBack:leftPanelView];
add a comment |
Swift
Insert a view below another view in the view hierarchy:
view.insertSubview(subview1, belowSubview: subview2)
Insert a view above another view in the view hierarchy:
view.insertSubview(subview1, aboveSubview: subview2)
Insert a subview at the specified index:
view.insertSubview(subview, at: index)
Move the specified subview so that it appears behind its siblings:
subview1.sendSubviewToBack(subview2)
Move the specified subview so that it appears on top of its siblings:
subview1.bringSubviewToFront(subview2)
Exchange the subviews at the specified indices:
view.exchangeSubview(at: index1, withSubviewAt: index2)
add a comment |
In Swift 4.2
self.view.sendSubviewToBack(leftPanelView)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f9790040%2fhow-to-add-a-view-behind-other-view-in-ios%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
try sendSubviewToBack
[self.view sendSubviewToBack:leftPanelView];
I accept your answer, coz you've sent it after 2 mins, I posted. I think it's fair.
– wzbozon
Apr 9 '12 at 17:06
10
This does not answer the question asked. All this does is move a view to the back of the subview chain. The answer below from He Shiming is correct.
– Rickster
Apr 7 '15 at 18:03
Thanks for the answer. It worked for me.
– Ramakrishna
Feb 6 '17 at 7:15
add a comment |
try sendSubviewToBack
[self.view sendSubviewToBack:leftPanelView];
I accept your answer, coz you've sent it after 2 mins, I posted. I think it's fair.
– wzbozon
Apr 9 '12 at 17:06
10
This does not answer the question asked. All this does is move a view to the back of the subview chain. The answer below from He Shiming is correct.
– Rickster
Apr 7 '15 at 18:03
Thanks for the answer. It worked for me.
– Ramakrishna
Feb 6 '17 at 7:15
add a comment |
try sendSubviewToBack
[self.view sendSubviewToBack:leftPanelView];
try sendSubviewToBack
[self.view sendSubviewToBack:leftPanelView];
answered Mar 20 '12 at 16:01
aderader
5,24411626
5,24411626
I accept your answer, coz you've sent it after 2 mins, I posted. I think it's fair.
– wzbozon
Apr 9 '12 at 17:06
10
This does not answer the question asked. All this does is move a view to the back of the subview chain. The answer below from He Shiming is correct.
– Rickster
Apr 7 '15 at 18:03
Thanks for the answer. It worked for me.
– Ramakrishna
Feb 6 '17 at 7:15
add a comment |
I accept your answer, coz you've sent it after 2 mins, I posted. I think it's fair.
– wzbozon
Apr 9 '12 at 17:06
10
This does not answer the question asked. All this does is move a view to the back of the subview chain. The answer below from He Shiming is correct.
– Rickster
Apr 7 '15 at 18:03
Thanks for the answer. It worked for me.
– Ramakrishna
Feb 6 '17 at 7:15
I accept your answer, coz you've sent it after 2 mins, I posted. I think it's fair.
– wzbozon
Apr 9 '12 at 17:06
I accept your answer, coz you've sent it after 2 mins, I posted. I think it's fair.
– wzbozon
Apr 9 '12 at 17:06
10
10
This does not answer the question asked. All this does is move a view to the back of the subview chain. The answer below from He Shiming is correct.
– Rickster
Apr 7 '15 at 18:03
This does not answer the question asked. All this does is move a view to the back of the subview chain. The answer below from He Shiming is correct.
– Rickster
Apr 7 '15 at 18:03
Thanks for the answer. It worked for me.
– Ramakrishna
Feb 6 '17 at 7:15
Thanks for the answer. It worked for me.
– Ramakrishna
Feb 6 '17 at 7:15
add a comment |
Besides addSubview
, there are other methods you can rely on to add your view:
– insertSubview:aboveSubview:
– insertSubview:belowSubview:
– insertSubview:atIndex:
You can control the index (actually z-index, or layer order) of the view using these methods.
1
For meinsertSubview:belowSubview:
solved the problem! Thx
– Alex Cio
Oct 22 '14 at 12:31
1
This should be the right answer. the above answer doesn't answer what was asked.
– MarkosDarkin
Oct 25 '17 at 12:41
add a comment |
Besides addSubview
, there are other methods you can rely on to add your view:
– insertSubview:aboveSubview:
– insertSubview:belowSubview:
– insertSubview:atIndex:
You can control the index (actually z-index, or layer order) of the view using these methods.
1
For meinsertSubview:belowSubview:
solved the problem! Thx
– Alex Cio
Oct 22 '14 at 12:31
1
This should be the right answer. the above answer doesn't answer what was asked.
– MarkosDarkin
Oct 25 '17 at 12:41
add a comment |
Besides addSubview
, there are other methods you can rely on to add your view:
– insertSubview:aboveSubview:
– insertSubview:belowSubview:
– insertSubview:atIndex:
You can control the index (actually z-index, or layer order) of the view using these methods.
Besides addSubview
, there are other methods you can rely on to add your view:
– insertSubview:aboveSubview:
– insertSubview:belowSubview:
– insertSubview:atIndex:
You can control the index (actually z-index, or layer order) of the view using these methods.
answered Mar 20 '12 at 16:03
He ShimingHe Shiming
4,33932653
4,33932653
1
For meinsertSubview:belowSubview:
solved the problem! Thx
– Alex Cio
Oct 22 '14 at 12:31
1
This should be the right answer. the above answer doesn't answer what was asked.
– MarkosDarkin
Oct 25 '17 at 12:41
add a comment |
1
For meinsertSubview:belowSubview:
solved the problem! Thx
– Alex Cio
Oct 22 '14 at 12:31
1
This should be the right answer. the above answer doesn't answer what was asked.
– MarkosDarkin
Oct 25 '17 at 12:41
1
1
For me
insertSubview:belowSubview:
solved the problem! Thx– Alex Cio
Oct 22 '14 at 12:31
For me
insertSubview:belowSubview:
solved the problem! Thx– Alex Cio
Oct 22 '14 at 12:31
1
1
This should be the right answer. the above answer doesn't answer what was asked.
– MarkosDarkin
Oct 25 '17 at 12:41
This should be the right answer. the above answer doesn't answer what was asked.
– MarkosDarkin
Oct 25 '17 at 12:41
add a comment |
Oh, I found a solution myself. I added after this:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view addSubview:leftPanelView];
this line:
[self.view sendSubviewToBack:leftPanelView];
add a comment |
Oh, I found a solution myself. I added after this:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view addSubview:leftPanelView];
this line:
[self.view sendSubviewToBack:leftPanelView];
add a comment |
Oh, I found a solution myself. I added after this:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view addSubview:leftPanelView];
this line:
[self.view sendSubviewToBack:leftPanelView];
Oh, I found a solution myself. I added after this:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view addSubview:leftPanelView];
this line:
[self.view sendSubviewToBack:leftPanelView];
answered Mar 20 '12 at 15:59
wzbozonwzbozon
8,78145860
8,78145860
add a comment |
add a comment |
Swift
Insert a view below another view in the view hierarchy:
view.insertSubview(subview1, belowSubview: subview2)
Insert a view above another view in the view hierarchy:
view.insertSubview(subview1, aboveSubview: subview2)
Insert a subview at the specified index:
view.insertSubview(subview, at: index)
Move the specified subview so that it appears behind its siblings:
subview1.sendSubviewToBack(subview2)
Move the specified subview so that it appears on top of its siblings:
subview1.bringSubviewToFront(subview2)
Exchange the subviews at the specified indices:
view.exchangeSubview(at: index1, withSubviewAt: index2)
add a comment |
Swift
Insert a view below another view in the view hierarchy:
view.insertSubview(subview1, belowSubview: subview2)
Insert a view above another view in the view hierarchy:
view.insertSubview(subview1, aboveSubview: subview2)
Insert a subview at the specified index:
view.insertSubview(subview, at: index)
Move the specified subview so that it appears behind its siblings:
subview1.sendSubviewToBack(subview2)
Move the specified subview so that it appears on top of its siblings:
subview1.bringSubviewToFront(subview2)
Exchange the subviews at the specified indices:
view.exchangeSubview(at: index1, withSubviewAt: index2)
add a comment |
Swift
Insert a view below another view in the view hierarchy:
view.insertSubview(subview1, belowSubview: subview2)
Insert a view above another view in the view hierarchy:
view.insertSubview(subview1, aboveSubview: subview2)
Insert a subview at the specified index:
view.insertSubview(subview, at: index)
Move the specified subview so that it appears behind its siblings:
subview1.sendSubviewToBack(subview2)
Move the specified subview so that it appears on top of its siblings:
subview1.bringSubviewToFront(subview2)
Exchange the subviews at the specified indices:
view.exchangeSubview(at: index1, withSubviewAt: index2)
Swift
Insert a view below another view in the view hierarchy:
view.insertSubview(subview1, belowSubview: subview2)
Insert a view above another view in the view hierarchy:
view.insertSubview(subview1, aboveSubview: subview2)
Insert a subview at the specified index:
view.insertSubview(subview, at: index)
Move the specified subview so that it appears behind its siblings:
subview1.sendSubviewToBack(subview2)
Move the specified subview so that it appears on top of its siblings:
subview1.bringSubviewToFront(subview2)
Exchange the subviews at the specified indices:
view.exchangeSubview(at: index1, withSubviewAt: index2)
edited Dec 2 '18 at 18:45
answered Jul 4 '18 at 20:05
xmasalovxmasalov
13135
13135
add a comment |
add a comment |
In Swift 4.2
self.view.sendSubviewToBack(leftPanelView)
add a comment |
In Swift 4.2
self.view.sendSubviewToBack(leftPanelView)
add a comment |
In Swift 4.2
self.view.sendSubviewToBack(leftPanelView)
In Swift 4.2
self.view.sendSubviewToBack(leftPanelView)
answered Nov 14 '18 at 13:17
Vinoth VinoVinoth Vino
3,04332636
3,04332636
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f9790040%2fhow-to-add-a-view-behind-other-view-in-ios%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Check if this works : [self.navigationController.view insertSubview: <subview> belowSubview:self.navigationController.navigationBar];
– Jayprakash Dubey
May 6 '16 at 6:20