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.
Related
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!");
}];
I'm using the following code to zoom/enlarge an image from within a table view. I would like it to enlarge out to full screen. the current problem is that when it enlarges it enlarges only within the table cell (and as a result is partially hidden beneath the next table cell) instead of the full view.
-(void)zoomPhotoMethod :(id) sender
{
UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) sender;
NSLog(#"Tag = %d", gesture.view.tag);
userSubmittedImageView = (UIImageView *)gesture.view;
if (!isFullScreen) {
[UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
//save previous frame
prevFrame = userSubmittedImageView.frame;
UIView *popupImageViewForTableCell = [[UIView alloc] initWithFrame: CGRectMake ( 0, 0, 320, 500)];
[userSubmittedImageView setFrame:[popupImageViewForTableCell bounds]];
}completion:^(BOOL finished){
isFullScreen = TRUE;
}];
return;
}
else{
[UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
[userSubmittedImageView setFrame:prevFrame];
}completion:^(BOOL finished){
isFullScreen = FALSE;;
}];
return;
}
}
updated code:
-(void)zoomPhotoMethod :(id) sender
{
UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) sender;
NSLog(#"Tag = %d", gesture.view.tag);
userSubmittedImageView = (UIImageView *)gesture.view;
if (!isFullScreen) {
[UIView animateWithDuration:0.3 delay:0 options:0 animations:^{
//save previous frame
prevFrame = userSubmittedImageView.frame;
newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)];
[self.view addSubview:newView];
UIView *popupImageViewForTableCell = [[UIView alloc] initWithFrame: CGRectMake ( 0, 0, 320, 500)];
[userSubmittedImageView setFrame:[popupImageViewForTableCell bounds]];
[newView addSubview:userSubmittedImageView];
[userSubmittedImageView setFrame:[newView bounds]];
}completion:^(BOOL finished){
isFullScreen = TRUE;
}];
return;
}
else{
[UIView animateWithDuration:0.3 delay:0 options:0 animations:^{
[userSubmittedImageView setFrame:prevFrame];
[newView setFrame:prevFrame];
}completion:^(BOOL finished){
isFullScreen = FALSE;;
}];
return;
}
}
What's happening is that you are still a subview of the tableview cell, so it's not going to be able to go outside of those bounds without being clipped.
To do what you want to do, you're going to have to:
Create a new UIImageView outside of your table view (add it as a subview outside of the tableview).
Set the image in the image view to the same image that you have in the tableview cell.
Start it at the same size and position as your tableview cell image.
Animate it up to where you want it.
When it's time to remove it, move it back down to the original tableview cell image.
Discard the imageview.
One way would be to use a copy of the image and place it outside the cell just above your original and animate this second image to full screen.
Another way would be to increase the tableView rowHeight and reload the section.
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.
In a UIView subclass I have this:
self.frontImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"front"]];
self.backImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"back"]];
[self addSubview:self.backImageView];
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[self.backImageView removeFromSuperview];
[self addSubview:self.frontImageView];}
completion:^(BOOL finished){
//nothing
}];
But I don't get the flip animation. The front image view just appears immediately. What am I doing wrong?
You are making a silly mistake using
animateWithDuration:delay:options:animations:completion:
instead of
transitionFromView:toView:duration:options:completion:
Your code should be:
[UIView transitionFromView:backImageView
toView:frontImageView
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished) {
// animation completed
}];
I'm new iphone developer i have problem uiview animation for ipad landscape mode.i have two view view1(like a split view) and view2(covered remaining window).when i touch move right to left view2 it will be overriding the view1 with moving animation.at same time when i touch move left to right view2 come and fit the old position.please share your ideas
With Regards,
Rajesh.
Hi all i found the answer finally,
- (void)viewDidLoad
{
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(rightSwipeHandle:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[recognizer setNumberOfTouchesRequired:1];
[secondView addGestureRecognizer:recognizer];
[recognizer release];
UISwipeGestureRecognizer *recognizerleft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(leftSwipeHandle:)];
[recognizerleft setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[recognizerleft setNumberOfTouchesRequired:1];
[secondView addGestureRecognizer:recognizerleft];
[recognizerleft release];
[self.view addSubview:secondView];
[super viewDidLoad];
}
//To set the frame position of the view
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
NSLog(#"rightSwipeHandle");
[UIView beginAnimations:#"viewanimations" context:nil];
[UIView setAnimationDuration:0.8];
[UIView setAnimationDelegate:self];
secondView.frame=CGRectMake(360, 0, 660, 768);
[UIView commitAnimations];
}
//To set the frame position of the view
- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
NSLog(#"leftSwipeHandle");
[UIView beginAnimations:#"viewanimations" context:nil];
[UIView setAnimationDuration:0.8];
[UIView setAnimationDelegate:self];
secondView.frame=CGRectMake(200, 0, 858, 768);
[UIView commitAnimations];
}
if i understand correctly, you want a sliding animation between 2 views. if so:
Make a ViewController that will hold these two views. inside this view controller's .m file define a transition method that contains the following and gets called by your buttons/other action triggers:
CGFloat windowWidth = self.mainView.frame.size.width;
CGFloat windowHeight = self.mainView.frame.size.height;
CGRect offScreenLeft = CGRectMake(-1*windowWidth, 0.0, windowWidth, windowHeight);
CGRect onScreen = self.mainView.frame;
CGRect offScreenRight = CGRectMake(windowWidth, 0.0, windowWidth, windowHeight);
if (direction == rightToLeft)
{
rightView.frame = offScreenRight;
[self.view addSubview:rightView];
[UIView animateWithDuration:0.65
animations:^{
leftView.frame = offScreenLeft;
rightView.frame = onScreen;
}
completion:^(BOOL finished){
[leftView removeFromSuperview];
}];
}else if (direction == leftToRight){
self.leftViewController.view.frame = offScreenLeft;
[UIView animateWithDuration:0.65
animations:^{
rightView.frame = offScreenRight;
leftView.frame = onScreen;
}
completion:^(BOOL finished){
[rightView removeFromSuperview];
}];
}
}
In general, make sure you are adding your subview to the view currently on screen, and make sure you set the appropriate bounds. Check that your view is not nil:
if(myView){
// not nil. thats good
}else {
// nil. this is bad. make sure myView is being initialized properly (if at all)
}
Finally, make sure neither the opacity nor the alpha property on your subview is set to 0 (you'll want these at 1 if you want it to show up completely and between 0 and 1 for a transparency effect).