I'm a newbie in iOS.
I have 5 views, one mainview and the others are like thumbnails. How can I replace view.
For example, if mainview(view1) has picture 1, view2 has picture 2, view3 has picture 3 etc.
How can I replace picture 1 with picture 2 so that View2 come in to the mainview?
Could some one help me to solve this problem?
Yes this could be done esily like this
View_1 is the first view
View_2 is the second view
containerView is the main super view for View_1
View_1 is the currently visible view
[UIView beginAnimations:#"doTheFlipping" context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationDelay:0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(myTransitionDidStop:finished:context:)];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:containerView cache:YES];
[View_1 removeFromSuperview];
[containerView addSubview:View_2];
[UIView commitAnimations];
This will create a flip view for view 1 to view 2
you not use separate views for this. see this page and download sample code from here to see detail. this is pageControl
http://developer.apple.com/library/ios/#samplecode/PageControl/Introduction/Intro.html
Related
I've just started objective C and I'm enhancing a current iPhone app. Previous codes were done by someone else. I'm trying to switch views back - and add a page curl animation in, but when I try to go back (removefromsuperview) my screen just goes white. I understand that I'm referring to the wrong view but I have no idea how to refer it to the right one.
-(IBAction)switchBack{
[UIView beginAnimations:#"flipview" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView: self.view.superview cache:YES];
//[self.navigationController popToRootViewControllerAnimated:YES];
[self.view removeFromSuperview];
[UIView commitAnimations];
}
The commented out popToRootViewController allows me to go back to the previous page. Any help would be really appreciated. I'm going crazy with all this views >< Thanks!
Try something like this:
[UIView transitionWithView:self.navigationController.view duration:1.0 options:UIViewAnimationOptionTransitionCurlDown
animations:^{
[self.navigationController popToRootViewControllerAnimated:NO];
}
completion:NULL];
that happened because you're trying to remove the view from its superview, which is not the way it is added before, don't use removeFromSuperView if you didn't use addSubview when showing the view it self.
you should add this code to the parent which calls your current view
viewNotLoggedHome.modalTransitionStyle =
UIModalTransitionStylePartialCurl;
this way you've stated a "partial curl" transition animation for the view u're pushing
and just delete all your animation block on switchBack function so it only consist of
-(IBAction)switchBack
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
Instead of usign self.view which is a reference to your superview, you need to use the name of the view you want to use.
f.e. :
- If you have view1 and view2
- you can delete view1 by using
[view1 removeFromSuperview];
I did some digging around about this, but nothing really seems to answer my particular question (not even this: Is it possbile to removeFromSuperview with Animation?).
Basically, my app starts with a welcome screen, where a user clicks on "sign in", then goes to the sign in view, then getting to a tab bar view, which is the actual app.
The way I did it, is that I wrote a custom class - TabBarController, which sets up all the tabs and their respective view controllers. Now, when the user clicks on "sign in" i am calling removeFromSuperview and present the tabbar.
I am trying to find a way to animate the transition from the sign in page to the tab bar. I tried some proposed solutions around here, but none seems to do the job. Here is my code in the signin.m view controller. I am looking to animate out the current view (ideally, not just by fading out, but more cool stuff like flips, etc.).
//when done signing in --> go to the tab bar view
-(IBAction)done:(id)sender {
TabBarController *tabController = [[TabBarController alloc] init];
[UIView beginAnimations:#"removeWithEffect" context:nil];
[UIView setAnimationDuration:4.0];
self.parentViewController.view.frame = CGRectMake(0,0,320,480);
self.parentViewController.view.alpha = 1.0f;
[UIView commitAnimations];
[self.parentViewController.view performSelector:#selector(removeFromSuperview) withObject:nil afterDelay:2.5f];
[self presentModalViewController:tabController animated:YES];
}
Appreciate any help!
That can't work that way. presentModalViewController dislpays the view of a viewController over the own view. It won't replace the source viewController (self).
Since you remove self.parentViewController.view from the view hierarchy, it can't present your tabController modally because you have removed self.
Anyway, i would recommend you another way to achieve your view layout:
Create a tabBarViewController and add its view to a rootView (self.window in the app delegate or whatever you are using now). Then add your login-view to the same view. Due the view hierarchy, the login-view will be displayed above the tabBar.view. And the done button should be implemented this way: (i'm using block syntax for animation as it should be)
-(IBAction)done:(id)sender {
[UIView animateWithDuration:1.0
animations:^{
self.view.frame = CGRectMake(0, 480, 320, 480);
self.view.alpha = 0.0
}
completion:^(BOOL finished){
[self.view removeFromSuperView];
}
];
}
You can animate more things than just the alpha, size or position. Just take a look about animations in the documentation. I guess, you'll be interested in view.transform to commit flip animations. ;)
This is how you have to remove the view after animating it.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelay:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:myView];
[UIView setAnimationDidStopSelector:#selector(removeFromSuperview)];
[UIView commitAnimations];
Hope this helps.
Happy coding.
this feels like a beginner question, but since I am not able to get it working in the intended-fashion, I am hoping somewhere out there is able to point me in the right direction.
What I am trying to achive is a transition of a view inside a view.
I fundamentally want to replace a view inside a view with another view(controller?!?) 's content.
lets say, I have an image of a book and I want to do a transition inside the book to another page (going from the calendar-view to the detailed daily view for example). I only want the "book-content"(white content area) to be included in that transition, and not the whole book itself(whole screen).
I can do a transition with the same view, no problem, but I dont get it working trying to replace the view with a completly different view.
It didnt matter having the views in seperate viewcontrollers, or all the views in one viewcontroller, so I were not able to get it working yet, but even worse, I am running out of ideas.
So HELP! If please somebody out there could be so kind and tell me what I am doing wrong.
Suggestions also very much appreciated.
Thanks!!
Tom
Maybe you could hide one view then show the other using a UIView Animations block.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view1.view cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view2.view cache:YES];
[UIView setAnimationDuration: 1.5];
[UIView commitAnimations];
view1.view.hidden = YES;
view2.view.hidden = NO;
Edit: Is this what you were looking for?
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[view1 viewWillDisappear:YES];
[view2 viewWillAppear:YES];
view1.view.hidden = YES;
view2.view.hidden = NO;
[view1 viewDidDisappear:YES];
[view2 viewDidAppear:YES];
[UIView commitAnimations];
Or, you could use something like this:
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[view1 removeFromSuperview];
[mySuperview addSubview:view2];
}
completion:nil];
Check out the exchangeSubviewsAtIndex: method in the UIView class. Just set up the 2 views that you want to transition from and to as subviews of another view; then call this method on that parent view.
Suppose you have a view controller with two views, A and B. They have identical frames so they occupy the same space in the controller's view, for your purposes displaying a page of a book. You want to display one and transition to the other.
One way would be to set the alpha property of one to 1.0 (opaque) and the other to 0.0 (transparent). Because this property can be animated you could do a fade from one to the other using a beginAnimations:context/commitAnimations, or use one of the block methods like the docs advise.
Another way would be to animate a change in frame in the two views. Set up the views so that one has a frame such that it is in the right place to display, the other has the same frame but with frame.origin.x equal to frame.size.width - it will be hidden because it is off-screen or hidden behind some other view. Animate the frame in by setting view A's frame.origin.x to -frame.size.width and frame B's frame.origin.x to the display position x origin. Then set (no animation) frame A's frame.origin.x to frame.origin.width again, update its content and you are ready to slide another page in from the right.
iPhone / Objective-C
On my view a little "hover" view appears after a user clicks on a button on the main view. When the user clicks this subview I want the subview to FlipFromRight to another view (same size). The main view underneath should stay.
viewHot and viewCold are the subviews viewMain is the main one.
Is this possible?
Create another empty view in viewMain called viewHover and position it where you want the hover views to show. Then in IB add either viewHot or viewCold (not both) as a subview of viewHover.
Then call a method like this to flip the views:
-(void)flipViews
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:viewHover cache:YES];
if ([viewHot superview])
{
[viewHot removeFromSuperview];
[viewHover addSubview:viewCold];
[viewHover sendSubviewToBack:viewHot];
}
else
{
[viewCold removeFromSuperview];
[viewHover addSubview:viewHot];
[viewHover sendSubviewToBack:viewCold];
}
[UIView commitAnimations];
}
I'm using the following code to make a small view disappear at the bottom of the screen:
int y_dest = self.application.windows.frame.size.height;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.33f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(closeAnimationDidStop:finished:context:)];
self.view.frame = CGRectMake(0, y_dest, self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
This works perfectly when the view is at the bottom of the screen but now I have to add it to the window above a TabBar meaning that the view is now animated over the top of the tabbar rather than behind it. Is there any way to have the view "disappear" behind the tabbar?
I've tried a combination of things so far including creating a "mask" view of the same size as the animated view and placing that in the window but for some reason that view did not appear at all. I also tried using insertSubview:belowSubview which made no difference. I'm sure I must be missing something here.
Thanks in advance!enter code here
Is it:
[self bringSubviewToFront:yourView] you are looking for?