I am adding a subview to my finalview which is used to change prefrences on the app.
I add it like this from my finalview
getPrefrencesViewController = [[GetPrefrencesViewController alloc] init];
getPrefrencesViewController.view setBackgroundColor:[UIColor clearColor]];
getPrefrencesViewController.view.frame = CGRectMake(0.0, 480.0, 320.0, 480.0);
getPrefrencesViewController.prefToolBar.frame = CGRectMake(0.0, 9.0, 320.0, 45.0);
[getPrefrencesViewController.view addSubview:getPrefrencesViewController.prefToolBar];
getPrefrencesViewController.prefTableView.frame = CGRectMake(0.0, 54.0, 320.0, 435.0);
[getPrefrencesViewController.view addSubview:getPrefrencesViewController.prefTableView];
[self.navigationController.view insertSubview:getPrefrencesViewController.view aboveSubview:self.navigationController.view];
[UIView animateWithDuration:0.3
delay:0.0f
options:UIViewAnimationOptionCurveEaseIn
animations:^{
getPrefrencesViewController.view.frame = CGRectMake(0.0, 10.0, 320.0, 480.0);
} completion:^(BOOL finished) {
if (finished) {
NSLog(#"YAY!");
}
}];
}
This works fine...
When the new view is added as a subview I have a UIToolBar with two buttons save and cancel, when the user touches cancel this code is used
- (IBAction)cancleUIButton:(id)sender {
//unload portrait view
[UIView animateWithDuration:0.4
delay:0.0f
options:UIViewAnimationOptionCurveEaseIn
animations:^{
self.view.frame = CGRectMake(0.0, 480.0, 320.0, 480.0);
} completion:^(BOOL finished) {
if (finished) {
// remove subView for superView
[self.view removeFromSuperview];
}
}];
}
as you can see i add the subview, animate it upwards, then when the user presses cancel I animate the view then remove it from superview.. however if I then load it again all the values I change but not saved are still changed, meaning the view is never removed.
I am hoping someone can tell me why this view is never getting removed? any help would be greatly appreciated.
Related
I adding view when btw is clicked from left to right and want to remove this view from right to left.
Below is my code while adding view from left to right
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main"
bundle: nil];
leftMenu = (LeftMenuViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"menuController"];
leftMenu.view.frame = CGRectMake(-320, 0, 320-50, self.view.frame.size.height);
[self addChildViewController:leftMenu];
[self.view addSubview:leftMenu.view];
[UIView animateWithDuration:0.3 animations:^{
leftMenu.view.frame = CGRectMake(0, 0, 320-50, self.view.frame.size.height);
hoverView.hidden = NO;
} completion:^(BOOL finished) {
[leftMenu didMoveToParentViewController:self];
}];
For removing this view from right to left what i have tried is:
self.view.frame = CGRectMake(320-50, 0, self.view.frame.size.width, self.view.frame.size.height);
[self willMoveToParentViewController:nil];
[UIView animateWithDuration:0.3 animations:^{
self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
} completion:^(BOOL finished) {
[self removeFromParentViewController];
[self.view removeFromSuperview];
}];
I want to remove view from right to left .Any help how to proceed further?
You must move your subview out of frame of superview, so set x-coordinate of your subview to negative value of it's own width. This will cause your view move from right to left out of view.
[self willMoveToParentViewController:nil];
[UIView animateWithDuration:0.3 animations:^{
self.view.frame = CGRectMake(-self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
} completion:^(BOOL finished) {
[self removeFromParentViewController];
[self.view removeFromSuperview];
}];
You can remove it like this:
CGRect napkinBottomFrame = Yourview.frame;
napkinBottomFrame.origin.x = 0;
[UIView animateWithDuration:0.3 delay:0.0 options: UIViewAnimationOptionCurveEaseOut animations:^{ Yourview.frame = napkinBottomFrame; } completion:^(BOOL finished){/*done*/}];
Swift 3 and 4 version:
leftMenu.didMove(toParentViewController: nil)
UIView.animate(withDuration: 0.3,
animations: {
self.leftMenu.view.frame = CGRect(x: -self.view.frame.width, y: 0, width: self.view.frame.width, height: self.view.frame.height)
},
completion: { finished in
self.leftMenu.view.removeFromSuperview()
self.leftMenu.removeFromParentViewController()
})
P.S. leftMenu should be class variable (property)
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
UIImageView *circleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"face.png"]];
circleView.frame = CGRectMake(0, 0, 200, 200);
circleView.layer.cornerRadius = 100;
circleView.center = self.view.center;
[self.view addSubview:circleView];
circleView.transform = CGAffineTransformMakeScale(0, 0);
[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:.5 initialSpringVelocity:1 options:0 animations:^{
circleView.transform = CGAffineTransformMakeScale(1, 1);
} completion:nil];
As you can see, I made a view called circleView in this animation method. Then, I created a touchesBegan method and I want to run through the animation again when touching the screen. How should I do that?
As Sujay said, create a new method and put below lines inside that method. Call that method from touchBegan method.
circleView.transform = CGAffineTransformMakeScale(0, 0);
[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:.5 initialSpringVelocity:1 options:0 animations:^{
circleView.transform = CGAffineTransformMakeScale(1, 1);
} completion:nil];
I did it. I created 2 properties and I made an animation where it gets small, then another animation that makes to make it bigger.
I am having one UIButton on navigation bar as right bar button item.
I want to show one view when I click on the UIButton,
and that view should appear animating from right to left and stops to perform some operations for user.
when user is done from his work on the view he will click on same button and view will hide animating from right to left.
I tried to load view normally I get succeed in it,
when I apply animation
view animates from right to left and disappears.
I am new to this animation scenario.
So can anyone please guide me to animate view and show hide action on same button.
Here is the code that I tried,
-(IBAction)showView :(id)sender
{
CGRect screen = [[UIScreen mainScreen]applicationFrame];
UIView *quizInfoViewObj;
quizInfoViewObj = [[UIView alloc]init];
quizInfoViewObj.frame = CGRectMake(70, 0, 250, 480);
quizInfoViewObj.backgroundColor = [UIColor orangeColor];
[UIView beginAnimations: nil context: NULL];
[UIView setAnimationDelegate: self];
[UIView setAnimationDidStopSelector: #selector(pushAnimationDidStop:finished:context:)];
quizInfoViewObj.center = self.view.center;
quizInfoViewObj.center = CGPointMake(self.view.center.x - CGRectGetWidth(self.view.frame), self.view.center.y);
[UIView commitAnimations];
[self.view addSubview:quizInfoViewObj];
}
here how I want...
This code might help you.
-(IBAction)showView :(id)sender
{
UIButton *button = (UIButton *)sender;
if ([button isSelected] == NO) {
CGRect screen = [[UIScreen mainScreen]applicationFrame];
// UIView *quizInfoViewObj; // use this line in .h file variables declaration
quizInfoViewObj = [[UIView alloc]init];
quizInfoViewObj.frame = CGRectMake(self.view.frame.width, 0, 250, 480);
quizInfoViewObj.backgroundColor = [UIColor orangeColor];
[self.view addSubview:quizInfoViewObj];
[UIView beginAnimations: nil context: NULL];
quizInfoViewObj.frame = CGRectMake(70, 0, 250, 480);
[UIView commitAnimations];
}
else {
[UIView beginAnimations: nil context: NULL];
[UIView setAnimationDelegate: self];
[UIView setAnimationDidStopSelector: #selector(pushAnimationDidStop:finished:context:)];
// In pushAnimationDidStop:finished:context method remove quizInfoViewObj from superview
quizInfoViewObj.frame = CGRectMake(self.view.frame.width, 0, 250, 480);
[UIView commitAnimations];
}
[button setSelected: ![button isSelected]];
}
Hi guys I have 2 UIViews. First UIView is moving via animation, but when it reaches second UIView it moving under it. How to move First UIView over the second UIView?
Here is my code (self.openView is first UIView, self.showView is second UIView):
- (void)cardImage:(NSString *)cardContent{
self.cardOpenImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:#"%#.png",cardContent]]];
self.cardOpenImage.frame = CGRectMake(0, 0, self.openView.frame.size.width, self.openView.frame.size.height);
UIImageView *cardBacksImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"cardbacks.png"]];
cardBacksImage.frame = CGRectMake(0, 0, self.openView.frame.size.width, self.openView.frame.size.height);
[self.openView addSubview:cardBacksImage];
[UIView transitionFromView:cardBacksImage
toView:self.cardOpenImage
duration:1
options:UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished) {
[self moveToLeft:nil finished:nil context:nil];
}];
}
- (void)moveToLeft:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView animateWithDuration:1.0
delay:0
options:(UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction)
animations:^{
[UIView setAnimationDelegate:self];
self.openView.center = CGPointMake(247, 180);
}
completion:^(BOOL finished){
NSLog(#"Move to left done");
}];
}
[self.openView.superview bringSubviewToFront:self.openView];
Will bring self.openView to the top of it's superview's view hierarchy. This will work assuming both of your UIViews are subviews of the same superview.
in my main view controller the button action is
-(IBAction)ChangeImage
{
UIImage *guns = [UIImage imageNamed:#"guns.png"]; // load our image resource
imageView = [[UIImageView alloc] initWithImage:guns];
NSLog(#"kaam hua..??");
[self.view addSubview:imageView];
[UIView transitionFromView:self.view
toView:imageView
duration:3.0f
options:UIViewAnimationOptionTransitionCrossDissolve
completion:nil];
NSLog(#"hfhjlkhbjhdfcvkbjnlkhgj");
}
i want to view the animation in slide view
is there any method to do this
can i chnage the UIViewAnimationOptionTransitionCrossDissolve to another one to show slide view
You can use UIViewAnimationOptionCurveEaseIn in animation option,
Try this,
CGRect or=self.view.frame;
CGRect basketTopFrame = self.view.frame;
basketTopFrame.origin.x = basketTopFrame.size.width;
self.view.frame = basketTopFrame;
[UIView animateWithDuration:0.2
delay:0.0
options: UIViewAnimationOptionCurveEaseIn
animations:^{
[self.view addSubview:imageView];
}
completion:^(BOOL finished){
NSLog(#"Done!");
}];