i am using following code , but subview is added below the the parentview not ON parent view(self.view)..any help please?
-(IBAction)okbutton:(id)sender
{
obj = [[imgViewNextController alloc] initWithNibName:#"green" bundle:nil];
obj.view.frame = self.view.frame;
[UIView beginAnimations:#"curldown" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[self.view addSubview:obj.view];
//[self.view insertSubview:obj.view aboveSubview:self.view];
[UIView commitAnimations];
Are you using a TableView ?
Some objects do (strange) things, so it may be related.
If possible give use more information about your self object.
By the way, you can try
[ self.view insertSubview: atIndex: ];
or
[ self.view insertSubview: aboveSubview: ];>
Good Luck !
Related
(i can't speak english well T.T)
I want fullscreen uiview in uiviewcontroller.
I use this code.
- (IBAction)addBtn:(id)sender {
addView = [[AddView alloc] initWithFrame:CGRectZero];
[[[UIApplication sharedApplication]delegate].window addSubview:addView];
addView.window.windowLevel = UIWindowLevelStatusBar;
[addView setAlpha:0.0f];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.35f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[addView setAlpha:1.0f];
[UIView commitAnimations];
}
when click button (+)
disappear status bar!!!!!!!
when i use same code in ios6, it's worked.
but in ios7 not worked.
why disappear status bar?
check my sorce code here.
write below code in viewdidLoad function...
your code......///
[addView setAlpha:0.5];// make addsubview alpha 0.5
Hope it will work...my friend!!!!
Happy Coding!!!!!!
Hi here is the code for your addBtn Method.
-(IBAction)addBtn:(id)sender {
addView = [[AddView alloc] initWithFrame:CGRectZero];
[[[UIApplication sharedApplication]delegate].window addSubview:addView];
addView.window.windowLevel = UIWindowLevelNormal;
[addView setAlpha:0.0f];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.35f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[addView setAlpha:1.0f];
[UIView commitAnimations];
}
It is working fine now.
You need to remove this line, addView.window.windowLevel = UIWindowLevelStatusBar;
- (IBAction)addBtn:(id)sender {
addView = [[AddView alloc] initWithFrame:CGRectZero];
[[[UIApplication sharedApplication]delegate].window addSubview:addView];
// addView.window.windowLevel = UIWindowLevelStatusBar;
[addView setAlpha:0.0f];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.35f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[addView setAlpha:1.0f];
[UIView commitAnimations];
}
I have code:
ListViewController * listViewController = [[ListViewController alloc] initWithNibName:#"ListViewController" bundle:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self viewWillDisappear:YES];
[listViewController viewWillAppear:YES];
self.view.hidden = YES;
listViewController.view.hidden = NO;
[self viewDidDisappear:YES];
[listViewController viewDidAppear:YES];
[UIView commitAnimations];
But it does not works, and listViewController does not displayed( Please, somebody can tell me the solution of this problem?
Try something like:
UIViewAnimationOptions ops = UIViewAnimationOptionTransitionFlipFromRight;
NSArray *temp = [[NSBundle mainBundle] loadNibNamed:#"NameOfNib" owner:self options:nil];
UIView* newView = [[temp objectAtIndex:0] view];
[UIView transitionFromView:self.view toView:newView duration:1.5 options:ops completion:nil];
self.view = newView; //Lets you control the new view from the current controller (you might want to save a reference to the old one if you need to change back)
As meronix said, non-block based animation is discouraged by Apple for the newer iOS versions. The above method is the "approved" way to do it.
Just so you know, the viewWillAppear, viewDidDisappear, and similar methods aren't methods that YOU call to make the view do things. They're called automatically when these things happen.
Your code had a few misunderstandings; I've commented on them below
//This looks fine (depending on what is in the nib)
ListViewController * listViewController = [[ListViewController alloc] initWithNibName:#"ListViewController" bundle:nil];
//Normally I use these to move things around, not change the view
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self viewWillDisappear:YES]; //These two methods aren't things that you call
[listViewController viewWillAppear:YES];
self.view.hidden = YES; //If you're flipping or otherwise moving a view out of
listViewController.view.hidden = NO; //sight then you don't need to hide/unhide views
[self viewDidDisappear:YES]; //Same as above, you don't call these
[listViewController viewDidAppear:YES];
[UIView commitAnimations];
Remove unnecessary code and just write this ...
ListViewController * listViewController = [[ListViewController alloc] initWithNibName:#"ListViewController" bundle:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self.view addSubview:listViewController.view];
[UIView commitAnimations];
it cannot work!
you just create and allocate a UIViewController, but never push it on any stacks, or add its view to a visible view.
when you set listViewController.view.hidden to no, you are not magically showing it on screen: you need to add its view to a view (or window) which is already on screen...
ps beginAnimation is deprecated: use blocks animation instead...
I have one view controller which contains two views (redView, blueView). The views are smaller than the main view.
I want to change from redView to blueView with animation. If use this none animation happens.
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight
forView:redView cache:YES]; // !!! I WILL CHANGE THIS
[self.view addSubview:blueView];
[redView removeFromSuperview];
[UIView commitAnimations];
In case I change the code to this, then the animation is ok but the whole mainView animates, something that i do not want to happen. I want only the subViews to flip. I should note that the 2 subviews are in the same position. (frame) Any ideas?
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight
forView:self.view cache:YES];
[self.view addSubview:blueView];
[redView removeFromSuperview];
[UIView commitAnimations];
Use Block animation instead of simple animation, from apple about simple animation "Use of the methods in this section is discouraged in iOS 4 and later"
Animation With Block's
[UIView transitionWithView:containerView
duration:1.25
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^
{
[redView removeFromSuperview];
[containerView addSubview:blueView];
}
completion:NULL];
containerView : is main view that will be animated.
Also add to your containerView redView,
that all :)
for more info look at
http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html
Solution Found:
I use a tempView for which i do the animation. Onto the tempView I add view1 and view2.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:tempView cache:YES];
[tempView addSubview:view2];
[view1 removeFromSuperview];
[UIView commitAnimations];
Extra: For a better animation you can use view1.visible = YES , NO instead of addSubview, removeFromSuperView, but they will be allocated all the time
In your first example it looks like you are deleting the redView before it can animate, try deleting it after the animation.
Code:
[UIView setAnimationDidStopSelector:#selector(removeRedViewFromSuperview)];
I am new with animations and I am using following code for Flip animation.
//MyMapView is UIView
MyMapView *aMapView = [[MyMapView alloc] initWithFrame:CGRectMake(0, 118, 321, 300) AndResArray:self.nearMeArray];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[[self view] addSubview:nearMeMap];
[UIView commitAnimations];
Its working fine. But whole view (with super view) Flips.
I only want to Flip subview that is MyMapView. The super view should not flip.
How to do this ???
EDITED
screen :
Below is main screen. When click on Map button I want to Flip only Brown part of the screen. Whole screen should not Flip.
Thanks...
I have figure out what's the problem. Please see the below code.
MapView.m
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code.
[self performSelector:#selector(addMapView) withObject:nil afterDelay:2.0];
}
return self;
}
- (void) addMapView {
//MyMapView is UIView
MKMapView *aMapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 321, 300)];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self cache:YES];
[self addSubview:aMapView];
[UIView commitAnimations];
}
And after that simply add object of MapView class where you want. like below.
//MyMapView is UIView
mapView *aMapView = [[mapView alloc] initWithFrame:CGRectMake(0, 118, 321, 300)];
[[self view] addSubview:aMapView];
vote up if this comment help you.
Thanks,
MinuMaster.
Matteo's answer is partially correct, but you need to set the animation on the view before you add it, or it won't work correctly. Like this:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:aMapView
cache:YES];
[self.view addSubview:aMapView];
[UIView commitAnimations];
Alternatively, you can use the block-based API introduced in iOS 4. Here's an example.
[UIView transitionWithView:aMapView
duration:1.0
options:UIViewAnimationTransitionFlipFromRight
animations:^{ [self.view addSubview:aMapView]; }
completion:^(BOOL f){ }
];
You need to add your view to self.view and then flip only aMapView:
MyMapView *aMapView = [[MyMapView alloc] initWithFrame:CGRectMake(0, 118, 321, 300) AndResArray:self.nearMeArray];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[self.view addSubView:aMapView];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:aMapView cache:YES];
[UIView commitAnimations];
Animated transitions like this animate the contents of a view. The system takes a snapshot of the contents at the beginning of the animation, another snapshot when you commit, and then animates between them. As you've seen with your original code, the entire view gets animated.
The simplest solution is probably just to introduce an intermediate view that's the size and position of where the map will go. Then animate that view as you add the map to it.
More info in the View Programming Guide's section on Creating Animated Transitions Between Views. Though the methods you're using have, in iOS 4, been superceded by new block-based versions.
-(void)viewDidLoad
{
[super viewDidLoad];
OptionView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 70)];
OptionView.backgroundColor=[UIColor blueColor];
OptionIsShow=false;
MoveView=[[UIView alloc] initWithFrame:CGRectMake(40, 40, 70, 70)];
[MoveView setBackgroundColor:[UIColor redColor]];
[self.view addSubview:MoveView];
}
-(void)ViewOrHideOptionView
{
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.MoveView cache:NO];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:1.0];
if(!OptionIsShow)
{
[self.MoveView addSubview:OptionView];
OptionIsShow=true;
}
else
{
[self.OptionView removeFromSuperview];
OptionIsShow=false;
}
[UIView commitAnimations];
}
I have a a tab bar that is made in the application delegate. By calling an action form a button click from one of the views loaded from the tab bar, I open the help screen but there is a jerking motion after loading.
forgive me for speaking informally..I have been picking my brain for the past few hours trying to figure this out..
-(void)flipToHelp {
HelpViewController *helpVariable = [[HelpViewController alloc] initWithNibName:#"HelpView" bundle:nil];
[self setHelpViewController:helpVariable];
[UIView beginAnimations:#"flipview" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:_window cache:YES];
[_window removeFromSuperview];
[helpVariable release];
self.window.rootViewController = self.HelpViewController;
[UIView commitAnimations];
}
Just to reiterate from the comment thread, you shouldn't be removing the window from its superview (it doesn't technically have a superview, so it's probably causing problems). And setting the window's rootViewController property should swap out the view hierarchies, Apparently the jerkiness comes from changing the window's rootViewController property, so maybe the solution is to avoid using that property. Here's what I think should be enough to accomplish this:
-(void)flipToHelp {
HelpViewController *helpVariable = [[HelpViewController alloc] initWithNibName:#"HelpView" bundle:nil];
[UIView beginAnimations:#"flipview" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:_window cache:YES];
[self.tabBarController removeFromSuperview];
[_window addSubview:helpVariable];
[UIView commitAnimations];
}
-(void)flipToHelp {
HelpViewController *helpVariable = [[HelpViewController alloc] initWithNibName:#"HelpView" bundle:nil];
[self setHelpViewController:helpVariable];
[helpVariable release];
[UIView beginAnimations:#"flipview" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:self.window
cache:YES];
self.window.rootViewController = self.HelpViewController;
[UIView commitAnimations];
}
How about this code? Does it still have a jerky animation?