hi all freind i want ask somthing, i try use label to swipe between views but i cant know the problem?
UISwipeGestureRecognizer *swipe;
swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(Gest_SwipedLeft:)];
[swipe setDirection:UISwipeGestureRecognizerDirectionLeft];
[label addGestureRecognizer:swipe];
[swipe release];
-(void)Gest_SwipedLeft:(UISwipeGestureRecognizer *) sender{
ThirdQPage* y=[[ThirdQPage alloc]init];
[self.view.superview addSubview:[y view]];
[self.view removeFromSuperview];}
You could do this -
- (void)hideView:(NSTimer *)timer
{
UIView *currentView = (UIView *)[timer userInfo];
[currentView addSubview:self.yourNewView];
return;
}
-(void)Gest_SwipedLeft:(UISwipeGestureRecognizer *) sender
{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:yourCurrentView cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1];
[NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:#selector(hideView:)
userInfo:yourCurrentView
repeats:NO];
[UIView commitAnimations];
}
You can use the same logic to swipe back from your newView to oldView.
Set label.userInteractionEnabled = YES. The default value for UILabel is NO, therefore all touches are ignored.
userInteractionEnabled A Boolean value that determines whether user
events are ignored and removed from the event queue.
#property(nonatomic, getter=isUserInteractionEnabled) BOOL
userInteractionEnabled
Discussion This property is inherited from the
UIView parent class. This class changes the default value of this
property to NO.
Related
I have an UIViewController which contains 2 UIScrollViews, scrollView1, scrollView2 for instance.
scrollView1 contains many UIViews, when tapping one of it's UIViews I want it to move into scrollView2
When tapping a UIView that belongs to scrollView1, a method inside the UIViewController is being called and the view is passed as a parameter.
In that method you should write something like:
[view removeFromSuperview];
[scrollView2 addSubview:view];
Edit:
For animated move you should try something like:
CGPoint originalCenter = [self.view convertPoint:view.center fromView:scrollView1];
[view removeFromSuperView];
[self.view addSubview:view];
view.center = originalCenter;
CGPoint destinationPointInSecondScrollView = ; // Set it's value
CGPoint finalCenter = [self.view convertPoint:destinationPointInSecondScrollView fromView:scrollView2];
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
view.center = finalCenter;
} completion:^(BOOL finished) {
[view removeFromSuperView];
[scrollView2 addSubview:view];
view.center = destinationPointInSecondScrollView;
}];
Supposing you have these two scrollViews declared as properties:
- (void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(viewTapped:)]
for (UIView *view in self.scrollView1.subviews) {
[view addGestureRecognizer:gesture];
}
}
- (void)viewTapped:(UITapGestureRecognizer *)gesture
{
UIView *view = gesture.view;
[self moveToScrollView2:view];
}
- (void)moveToScrollView2:(UIView *)view
{
[view removeFromSuperview];
[self.scrollView2 addSubview:view];
}
My first view contains a button and after pressing a button, i will end up with the second view. what I have done is
FirstViewController.m
- (void)pushToWishList {
SecondViewController *controller = [[SecondViewController alloc] initWithNibName:#"SecondView" bundle:nil ];
[UIView beginAnimations:#"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[self.view addSubview:controller.view];
[UIView commitAnimations];
}
SecondViewController is an UIViewController such that :
SecondViewController.h :
#interface SecondViewController :
UIViewController
SecondViewController.m
self.navigationController.navigationBarHidden = NO;
self.navigationItem.hidesBackButton = NO;
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
What is happening is the top navigation is disppearing and the UITableView in my second view can not be scrolled up and down. My program is crashed whenever I try to do this.
Please advice me on this issue. Any comments are welcomed here.
First off its easier to not addSubview: just use this code to turn your page:
- (IBAction)myCart:(id)sender; {
viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:viewController animated:YES];
}
This will allow your tableView to scroll! Also, your method return type is void, if you are using a button to call this method, you need to change the return type to IBAction which works for buttons.
I am trying to switch views, but I want the animation with the view lifts up and its like a piece of paper folding to see what is underneath.
Any tutorials or examples of how to get that view animation, if it is an animation, would be appreciated.
Actually the view that the maps app uses when you hit the button on the corner.
Something like this should work:
MyViewController *myView = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
myView.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(dismissModalViewControllerAnimated:)] autorelease];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:myView];
navigation.modalTransitionStyle = UIModalTransitionStylePartialCurl;
navigation.delegate = self;
[self presentModalViewController:navigation animated:YES];
The key here is the modalTransitionStyle property needs to be set to UIModalTransitionStylePartialCurl before presenting the modal view.
More info here: UIViewController Class Reference (look for modalPresentationStyle, modalTransitionStyle, presentModalViewController:animated:, and dismissModalViewControllerAnimated:).
There are two basic ways of doing this, the old one which is no longer recommended:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:containerView cache:YES];
[containerView addSubview:subview];
[UIView commitAnimations];
And the new one (It uses blocks which are supported from iOS 4 and on):
[UIView transitionWithView:containerView duration:0.5
options:UIViewAnimationOptionTransitionCurlDown
animations:^ { [containerView addSubview:subview]; }
completion:nil];
I have a UIViewController, a "switcher" that will basically just rotate a view from one to another.
It all works great, except that the view that I am transitioning to is a UIViewController which holds a UITableViewController. For some reason, when the animation "flips", the navigation bar is invisible, and once the animation completes the navigation bar just appears.
It really doesn't look good and I was wondering if anyone knew why I might be seeing this and how I could fix it?
Thanks,
--d
EDIT: Adding some code by request!
Switcher viewDidLoad method - Currently Initializing both of the ViewControllers because I thought it may help
[super viewDidLoad];
LogoView *logoController = [[LogoView alloc] init];
self.logoView = logoController;
[self.view insertSubview:logoView.view atIndex:0];
[logoController release];
MainController *vController = [[MainController alloc] init];
self.controller = vController;
[vController release];
switchTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(switchViews) userInfo:nil repeats:NO];
Switcher switchViews method
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if (self.controller.view.superview == nil)
{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[controller viewWillAppear:YES];
[logoView viewWillDisappear:YES];
[logoView.view removeFromSuperview];
[self.view insertSubview:controller.view atIndex:0];
[logoView viewDidDisappear:YES];
[controller viewDidAppear:YES];
}
[UIView commitAnimations];
MainController viewDidLoad method
CGRect frame = CGRectMake(0, 0, 320, 410);
FirstLevelController *controller = [[FirstLevelController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:controller];
navController.view.frame = frame;
navController.navigationBar.tintColor = [UIColor blackColor];
[controller release];
[self.view addSubview:navController.view];
Inside the FirstLevelController I just add the items to the table view... I've tried adding a navController.title = #"Home", but I am not even seeing the black navbar without text... it's just a big empty space.
Help is muchly appreciated!
Hah! I changed the animation "cache" from YES to NO, and it fixed it! Yay!
I have a UIView which has a button, On the button's tap I am showing a new UIView which contain a UINavigationBar and a UITableView. Is there any way to animate a flip effect on button's tap and load the view and also vice versa ?
Sure, here is some code that may help
- (void)flipAction:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.75];
// checks to see if the view is attached
[UIView setAnimationTransition:([logTextView superview] ?
UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)
forView:[self view] cache:YES];
[UIView setAnimationTransition:([logTextView superview] ?
UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)
forView:[[self navigationController] view] cache:YES];
if ([logTextView superview])
{
[logTextView removeFromSuperview];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"FTP Log", nil) style:UIBarButtonItemStyleBordered target:self action:#selector(viewFtpLog)];
}
else
{
[[self view] addSubview:logTextView];
[[[self navigationItem] rightBarButtonItem] release];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"Done", nil) style:UIBarButtonItemStyleDone target:self action:#selector(flipAction:)];
}
[UIView commitAnimations];
}
For you, you might want to get the UIView for your table view. The button is what triggers the flip