Say I have two view controllers, A and B. UIView instance viewObject is subview of A in the nib, with frame 0, 0, 100, 100.
Now I execute the following
[UIView animateWithDuration:0.5 animations:^{[viewObject setFrame:CGFrameMake(100, 100, 100, 100)];}];
It worked all fine. But when I call:
[self presentViewController:B animated:YES completion:NULL];
viewObject appears to jump back to the frame before the animateWithDuration:animations: message during the transition of the view controllers.
Likewise when I dismiss B the viewObject is at its position in the nib.
How do I make viewObject stay in the same place?
try to set
[viewObject setClipsToBounds:YES]
at least before the second animation. If you need it not to clip to bounds(because of shadows and such) you can reset the property to no after the second animation is completed.
It worked for me every time I had this problem.
Related
I have a view controller where the views are laid out manually (no xib). This is done in viewDidLayoutSubviews. I want to animate one of the views, but the animation doesn't work (no observable motion of the view) because viewDidLayoutSubviews appears to be called immediately as the animation begins.
Relevant portions of code:
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
logo.frame = CGRectMake(0, 0, 640, 360);
}
- (void)shrink
{
[UIView animateWithDuration:0.5 animations:^{logo.frame = CGRectMake(0, 0, 320, 180);}];
}
The shrink method is called when another timer fires, so it's not called straight away on view controller creation.
If I set up logo.frame elsewhere and remove that line from viewDidLayoutSubviews, then the animation works correctly.
What is the explanation for this behaviour, and what is a recommended way to work around it?
Have you tried to call animation method in viewDidApper ? Instead of use viewDidLayoutSubviews try to use viewDidLoad
For some reason i am not able two animate two subviews postion. I have wrote the following
[self addChildViewController:self.photosViewController];
[self.photosViewController.view setFrame:CGRectMake(0, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:self.photosViewController.view];
[UIView animateWithDuration:1 delay:0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
[self.stepsView setFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
[self.photosViewController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
}
completion:^(BOOL finished) {
if (finished) {
button.tag = 0;
}
}];
self.stepsView is an IBOutlet UIView and self.photosViewController.view is an child view controllers view that has been added to the view.
With the current code only the self.PhotosViewController.view animates. However if i comment out the line where i add the child view controllers view as a subview then the self.stepsView animates correctly.
Even if i add the child view controller and its view before this method is called the same error happens.
Need help as i ran in to this a couple of months back with another app and had to do a dirty hack to get around it and now want to solve this.
Thanks
In the section on view animation in the View Programming Guide there is a specific mention of how to animate subviews.
Basically, you should use transitionWithView:duration:options:animations:completion: rather than animateWithDuration:delay:options:animations:completion:.
The first view will not be visible, because its origin.y is beyond the height of the visible view. If it was not visible when the animation starts, you will of course see nothing.
The second view is changed to fill the screen. Again, what you see depends on its initial position.
I have a UIView configured through Storyboard. This view (self.view) has one child, a button (self.cartButton). Later in the code I add a subview to this view:
[self.view addSubview:self.cart.view];
I have the following method:
- (void)openCart
{
[UIView animateWithDuration:2 animations:^{
self.cartButton.frame = CGRectMake(0.0f, 0.0f, self.cartButton.frame.size.width, self.cartButton.frame.size.height);
self.cart.view.frame = CGRectMake(0.0f, 0.0f, self.cart.view.frame.size.width, self.cart.view.frame.size.height);
}];
}
I think it should move both objects to the top of the screen, but what really happens is that the cartButton animates to the bottom most position, and the cart view to the top. Why does this happen? Did I mess up the coordinate systems somewhere?
UPDATE: If I comment out the second line in the animation (animating the cart view), cartButton flies to the top.
UPDATE2: It has something to do with my cartView. It is a generic view (created in Storyboard). When I try to do the same animation for example with a NavigationController, it works.
UPDATE3: If my cart view has no subviews, it works fine. If it has anything in it (a button, navigationBar, anything...), it does not work.
I am using UIImagePickerController to take photo.The process is :
start a view with some controls.
addsubview on current view:
self.claim.view.frame = CGRectMake(0, 0, 1024, 50);
[self.view addSubview self.claim.view];
3.there is a Button in self.claim.view to start camera and it does start, but the problem is:the vision is only shows in the view area( 0, 0, 1024, 50 ),I can't see anything clear through the camera,why doesn't it fill the screen ?I try several ways but doesn't work.
My tries:
1. set property cameraOverlayView(manual said this property set a view to overlay the preview view.)
2. when press the button add another subview with frame(0,0,1024,768), and in new view delegate method*(void)viewDidAppear:(BOOL)animated**start the camera.
neither of them is helpful.Is there any possible way to make the camera full screen?
I had a similar issue before. It could be the view controller that you're doing your
[self presentViewController:imagePicker animated:YES completion:nil];
instead try to instantiate the imagePicker in another view controller and dismiss the current view controller. Hope this help.
I have a split view controller in my Ipad app, in which the detail view has subviews which are UITableView's.
The functionality I am trying to implement is to get an info view at the same position of a subview when a button(info button) on the subview is pressed. I need to get this info view by animation and that animation is that when the info button is pressed, that subview alone would flip (UIAnimationOptionFlipFromRight) and the info view would show...
This is how try to implement it -
-(void) showInfoView: (id)sender
{
infoView = [[InfoViewController alloc] initWithNibName:#"ViewViewController" bundle:nil];
infoView.view.frame = CGRectMake(250, 300, 200, 200);
[UIView transitionWithView:self.view duration:1
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[self.view addSubview:infoView.view];
}
completion:nil];
}
When I run the simulator and press the info button on any subview, what happens is that the animation happens perfectly, i.e. the subview flips from the right but the infoView is not getting displayed.
It would be great if someone could tell me where I am going wrong here.
The basic steps of performing an animation to onscreen is as follows:
Create the view.
Move it to the initial (offscreen) position
Add to the view hierarchy
Perform the animation.
It seems like you're skipping step 3 and possibly step 2.
Did you try setting the subview frame to the frame of your superview, i.e
info.View.frame = self.view.frame;