I have implemented nested UITableViews such that, on selecting a particular row from parent Data list, gets child nodes data from server and reloads them in same UITableview. I have given provision to go back to parent nodes using dictionary and everything working fine. I want Navigation Style animation when I move parent data list to child data list. Could someone please help me how to do this.
I have tried using following code UIViewAnimationOptionTransitionFlipFromLeft and UIViewAnimationOptionTransitionFlipFromRight animations it flips the view - I am looking for similar but without flip - simple navigation style animation like I want to pretend I am pushing another UITableView.
[UIView transitionWithView: self.listTableView
duration: 0.35f
options: UIViewAnimationOptionTransitionFlipFromLeft
animations: ^(void) {
[self.listTableView reloadData];
} completion: ^(BOOL isFinished){
}];
Here is Logic with Code.
you need to import QuartzCore framework in.h` for using below piece of Code.
AS #import
// Method to replace a given subview with another using a specified transition type, direction, and duration
-(void)replaceSubview:(UIView *)oldView withSubview:(UIView *)newView transition:(NSString *)transition direction:(NSString *)direction duration:(NSTimeInterval)duration
{
// Set up the animation
CATransition *animation = [CATransition animation];
// Set the type and if appropriate direction of the transition,
if (transition == kCATransitionFade)
{
[animation setType:kCATransitionFade];
}
else
{
[animation setType:transition];
[animation setSubtype:direction];
}
// Set the duration and timing function of the transtion -- duration is passed in as a parameter, use ease in/ease out as the timing function
[animation setDuration:duration];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[oldView layer] addAnimation:animation forKey:#"transitionViewAnimation"];
}
Call Above method when TableView row gets Clicked as below.
[self replaceSubview:thisTableView
withSubview:thisTableView
transition:kCATransitionPush
direction:kCATransitionFromLeft
duration:0.3];
//thisTableView is instance of UItableView.
Related
I trying to create activity indicator, currentView will be static and nextView will animate left to right, right to left, top to bottom and bottom to top.
I had written the code as below. The problem I am facing is, instead of all the four animations I am getting only one animation top to bottom animation. Can anyone help me how to run all the four animations one by one until a process is completed
statusImage = [UIImage imageNamed:#"image2.png"];
moveImage = [UIImage imageNamed:#"image1.png"];
currentView = [[UIImageView alloc]
initWithImage:statusImage];
nextView = [[UIImageView alloc]
initWithImage:moveImage];
//Add your custom activity indicator to your current view
[self.view addSubview:currentView];
[self.view addSubview:nextView];
CATransition *transition1 = [CATransition animation];
[transition1 setType:kCATransitionPush];
[transition1 setSubtype:kCATransitionFromLeft];
[transition1 setDuration:1];
[nextView.layer addAnimation:transition1 forKey:#"string1"];
CATransition *transition2 = [CATransition animation];
[transition2 setType:kCATransitionPush];
[transition2 setSubtype:kCATransitionFromRight];
[transition2 setDuration:1];
[nextView.layer addAnimation:transition2 forKey:#"string2"];
CATransition *transition3 = [CATransition animation];
[transition3 setType:kCATransitionPush];
[transition3 setSubtype:kCATransitionFromTop];
[transition3 setDuration:1];
[nextView.layer addAnimation:transition3 forKey:#"string3"];
CATransition *transition4 = [CATransition animation];
[transition4 setType:kCATransitionPush];
[transition4 setSubtype:kCATransitionFromBottom];
[transition4 setDuration:1];
[nextView.layer addAnimation:transition4 forKey:#"string4"];
Can anyone help me how to run all the four animations one by one until a process is completed
A layer can have only one transition animation at a time. There is no point supplying a key for a transition animation. The key will always really be kCATransition. Your string1 etc. are pointless; just use nil. Moreover, your code makes no sense; multiple animations attached to a layer causes those animations to be performed simultaneously (if possible), not successively.
You need to chain the animations. Set up your code like this:
Perform the first animation, giving it a completion handler. This completion handler is called when the first animation finishes.
In the completion handler, do the second animation, giving it a completion handler. This completion handler is called when the second animation finishes.
In the completion handler, do the third animation, giving it a completion handler. This completion handler is called when the third animation finishes.
In the completion handler, do the fourth animation.
I have an application of proof of simulated, which have some modules, and one of this is a screen which need be reloaded for exhibition of same data. Example: I have screen of the question and answers. Like below
Question: bla bla bla?
Item A: X
Item B: Y
Item c: Z
...
the screen remains the same, what needs to be change is the question and answer content item A, item B, etc..
And, I'm loading the informations "hardcode". I'm sure there are other better choice to make this ^^. I would like to use the same screen to load the features. How I can make this? I was looking to page controller, but it's not what I want, I would like to use a navigation controller to navigation with the screens. I have a dictionary of a list of all the questions with answers: itemA, itemB, etc. how I can load this in the "same screen" with the option of next > and < previous?
A simple one solution is create one UIView add all question and answer related views in it.
Create one UIView add all question and answer related views in it
Create next/previous UIButtons
Add and remove this view on next/previous events and reload inner view content.
Use below method for animation which looks like a navigation next/previous
In below method self.questionPaperView is a which will be animated and it contains all question and answer related views.
Note: Create a global variable for questionPaperView and for inner views. So you don't need to add questions/answers subviews every time you add/remove questionPaperView.
- (void) removeQuestionPaper {
[UIView animateWithDuration:0.35f animations:^{
[self.questionPaperView removeFromSuperview];
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
// Call data reload method here.
}];
}
- (void) addQuestionPaper {
[self.view addSubview:self.questionPaperView]
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionFade];
[animation setSubtype:kCATransitionFromRight]; // For previous use kCATransitionFromLeft
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:#"NextView"];
}
I have a UISegmentedControl that is shown/hide like a modal window. Initially it does not have a selected segment. In IB, the Value Changed event is wired to the method - (IBAction)cardClassificationChanged:(UISegmentedControl *)sender. Here is that method:
- (IBAction)cardClassificationChanged:(UISegmentedControl *)sender
{
NSLog(#"%d", sender.selectedSegmentIndex);
// block for updating the categorization of current card asynchronously
[self.cardActionSheet hideWithAnimation];
}
If I comment out the last line (the call to -hideWithAnimation), the selection changes as expected, everything works. However, with the call to that animation method, the UISegmentedControl selection will not visually change before the animation. Here is the hideWithAnimation method:
- (void)hideWithAnimation
{
CATransition *animation = [CATransition animation];
animation.type = kCATransitionFade;
animation.duration = globalAnimationLength;
[self.layer addAnimation:animation forKey:nil];
self.hidden = YES;
}
The next time this view appears (from a touch gesture), the UISegmentedControl will have the correct segment selected though.
It seems like I should not have to call setNeedsDisplay for the UISegmentedControl, but even when I experiment with it in the cardClassificationChanged method or the hideWithAnimation method, it does not refresh.
I'm obviously missing something related to the UI update, what do I need to call to update the UISegmentedControl selection before the animation?
I suggest you should use UIKit animations for fading out your control. Try the following code
- (void)hideWithAnimation
{
[UIView animateWithDuration:0.2
animations:^{
self.alpha = 0.;
} completion:^(BOOL finished) {
self.alpha = 1.;
self.hidden = YES;
}];
}
I've got a MainViewController that has many subViews. Basically, it's broken down into two panes. The panes are designed to look like clipboards. I'd like to hit a button and have the "paper" on one of the clipboards do a partial curl to reveal the page underneath.
This isn't a full Modal ViewController presentation situation.
I'm working with the following code, but the results are funky:
FlipView *flipView = [[FlipView alloc] init];
[self setFlipView:flipView];
[flipView setHidden:YES];
[flipView setFrame:[[self WhereAmI] frame]];
[[self view] addSubview:flipView];
[[self view] bringSubviewToFront:[self WhereAmI]];
[flipView setHidden:NO];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:1.0];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[animation setType:#"pageCurl"];
[animation setFillMode:kCAFillModeForwards];
[animation setEndProgress:0.9];
[animation setRemovedOnCompletion:NO];
[[self WhereAmI] setHidden:YES];
[[[self WhereAmI] layer] addAnimation:animation forKey:#"pageCurlAnimation"];
Basically, I'm trying to load my new view programmatically, slide it in behind the currently visible view and then curl up the view that's on top to reveal the view that's now underneath. I get somewhat of a partial curl animation, but the "page" that's curling up isn't opaque, which is odd. Also, when I don't set my view and label to be hidden, even though you see them curl up, you also still see them "underneath", which is also odd. Plus, I don't see the UILabel I placed in the XIB for the new view.
Any thoughts?
Thanks!
OK, so I've got a working solution, but it's not quite what I was hoping to do. I'd still love to figure out the solution to my original question, but here's what I'm doing for now:
The background image for my "base" view is an image of a spiral-bound notebook.
The background image for all other views is a screen shot of a page curl.
(By "background image", I mean a UIColor created with a patternImage.)
The code to transition views is:
- (IBAction)NavigationTabSelected:(id)sender
{
// Flipping views is driven by a SegmentedControl
int selected = [[self NavigationTabsSegmentedControl] selectedSegmentIndex];
int current = [[self ViewArray] indexOfObject:[self ActiveFlipView]];
UIView *newFlip = [[self ViewArray] objectAtIndex:selected];
BOOL up = selected > current;
[UIView animateWithDuration:1.0
animations:^{
[UIView setAnimationTransition:(up)?UIViewAnimationTransitionCurlUp:UIViewAnimationTransitionCurlDown forView:[self RightView] cache:YES];
[[self ActiveFlipView] removeFromSuperview];
[[self RightView] addSubview:newFlip];
}
completion:^(BOOL finished){
[self setActiveFlipView:newFlip];
}];
}
As you can see, tabs to the right of the current tab generate a "curl up" and tabs to the left of the current tab generate a "curl down". It's not quite what I wanted, but it serves my purpose.
Any better ideas?
have you considered loading it as a modal view?
- (void)yourFrontViewControllerMethod
{
YourBackViewController *bfvc = [[YourBackViewController alloc] init];
[bfvc setModalTransitionStyle:UIMoalTransitionStylePartialCurl];
[self presentViewController:bfvc];
[bvfc release];
}
This will give you the desired effect of a view curling up to reveal another view.
Also as a general rule of thumb we try not to create animations that way. Try using a block based method instead (eg [UIView AnimateWithDuration:....]);
Hope that helps :)
i want to slide in a menu from a side in a View after a buttonclick event. After another Buttonclick the menu should be slided out from the big View...
I experimented with CATransition but i can't solve this problem...
CATransition *animation = [CATransition animation];
[animation setDuration:1];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromBottom];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]] ;
[[menuView layer] addAnimation:animation forKey:#"#asdf"];
[menuView setCenter:CGPointMake([menuView center].x, [menuView center].y + 450)];
it work a bit, but i did not understand why.. :-/
If you want to implement it yourself one way you can go about it is create a custom view and add a button click event for a button in your view controller.
Also create a boolean variable to identify whether your custom view is visible or not.
On click, if menu view is not visible, then do this:
-(void)viewDidLoad
{
...
// ---------------------------------------------
// create the custom menu view off screen
// ---------------------------------------------
menuView = [[MenuView alloc] initWithFrame:CGRectMake(-320, 0, 320, 480)];
menuView.alpha = 0; // hide it so it doesn't show at the start, only show when slide in
[self.view addSubview:menuView];
...
}
-(void)toggleMenu
{
if(menuIsVisible)
{
menuIsVisible = NO;
[self hideMenu];
}
else
{
menuIsVisible = YES;
[self showMenu];
}
}
-(void)hideMenu
{
[UIView animateWithDuration:0.5 animations:^{
// note CGAffineTransforms doesn't use coordinates, they use offset
// so an offset of (0,0) would bring the menuView back to the coordinate
// when it was first instantiated, in our case, (-320, 0).
menuView.transform = CGAffineTransformMakeTranslation(0,0);
} completion:^{
// hide the menu
menuView.alpha = 0;
}];
}
-(void)showMenu
{
// show the menu
menuView.alpha = 1;
[UIView animateWithDuration:0.5 animations:^{
// note CGAffineTransforms doesn't use coordinates, they use offset
// so an offset of (320,0) from coordinate (-320,0) would slide the
// menuView out into view
menuView.transform = CGAffineTransformMakeTranslation(320,0);
}];
}
A Controller like ViewDeck will enable you to do that.
Edit:
I'm not sure what else to add to this, moderator. It's open source code that will add a menu that is controlled by a button which will slide in when clicked and slide out when clicked again, similar to what Facebook and Path have. You're also gaining the touch events with slide.
There's an example of how to use it on the github page here: https://github.com/Inferis/ViewDeck#how-to-use-it and also several examples projects available in the source code.