I have one table view and one imageview, each one takes half of the screen.
I am trying to animate an image view when the user swipes on the imageview and when table cell is selected.
I use this code:
#interface X()
#property (strong, nonatomic) IBOutlet UIImageView *ImagePreview;
#property (strong, nonatomic) IBOutlet UITableView *table;
#end
#implementation X
- (void)handleGestureRight:(UISwipeGestureRecognizer *)sender {
[self ShowAnimation:_ImageGalaryPreview];
}
-(void)ShowAnimation:(UIImageView *)view{
[UIView beginAnimations: #"Slide Image" context: NULL];
[UIView setAnimationDuration: 1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:view cache:NO];
[UIView commitAnimations];
}
#end
It works perfect when I call it after the swipe but when I call it from UITableView class instance it does not work!
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self ShowAnimation:_ImageGalaryPreview];
}
Can anyone tell me why ?!
Use your calling method as given below,It will definitely work.
-(void)stuff
{
[UIView beginAnimations: #"Slide Image" context: NULL];
[UIView setAnimationDuration: 1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:Ù€ImagePreview cache:NO];
[UIView commitAnimations];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSelectorOnMainThread:#selector(stuff) withObject:nil waitUntilDone:NO];
}
you just need to pass the view of tableview in place of imageView....check it works.. Enjoy
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[UIView beginAnimations: #"Slide Image" context: NULL];
[UIView setAnimationDuration: 1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView: tableView cache:NO];
[UIView commitAnimations];
}
Nothing happens when the user taps a table row because none of the lines in the didSelectRowAtIndexPath method includes anything that is related to indexPath.row. Maybe, try something like the following.
#interface ViewController () {
NSInteger selectedrow;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSIndexPath *selectedIndexPath = [table indexPathForSelectedRow];
selectedrow = indexPath.row;
if (indexPath.row >= 0) {
[UIView beginAnimations: #"Slide Image" context: NULL];
[UIView setAnimationDuration: 1];
...
...
ImagePreview = ... [array objectAtIndex:selectedrow]...
}
}
- (void)viewDidLoad {
selectedrow = -1;
}
Still, I don't know how your code has anything to do with UIImageView.
thanks for your response also I solve it with this code
[self performSelectorOnMainThread:#selector(stuff) withObject:nil waitUntilDone:NO];
thanks to #Hercules :)
Related
I have added a footer to the UITableView in plain style if the user clicks the textfield of last cell the tableview is not scrolling
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection: (NSInteger)section{
UIView *view =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
[view setBackgroundColor:[UIColor blackColor]];
return view;
}
if it is a sectioned table this works, please help
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if(textField == yourTextField){ /// here write name of your Textfield in which you want to scroll tableview
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
yourTableView.frame = CGRectMake(yourTableView.frame.origin.x, -160, yourTableView.frame.size.width, tblContactUS.frame.size.height);
[UIView commitAnimations];
}
return YES;
}
and put your TableView with previous frame then use bellow method
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
if(textField == yourTextField){ /// here write name of your Textfield in which you want to scroll down tableview
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
yourTableView.frame = CGRectMake(yourTableView.frame.origin.x, 0, yourTableView.frame.size.width, tblContactUS.frame.size.height);
[UIView commitAnimations];
}
return YES;
}
i hope this help you...
i need help here, i'm using a custom segue to push a view controller to another view controller.
when pushed using cutom segue, the uiactivityindicator will not animate automatically when view loaded.
however if i used the push method on the storyboard, the uiactivityindicator animate automatically.
what i had done wrong ?
-(void)perform {
UIViewController *sourceVC = (UIViewController *) self.sourceViewController;
UIViewController *destinationVC = (UIViewController *) self.destinationViewController;
[UIView transitionWithView:sourceVC.navigationController.view duration:0.5
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[sourceVC.navigationController pushViewController:destinationVC animated:NO];
//NSLog(#"count of subview %i", [self.view.subviews count]);
}
completion:NULL];
}
Try this:
UIViewController *sourceVC = (UIViewController *) self.sourceViewController;
UIViewController *destinationVC = (UIViewController *) self.destinationViewController;
[UIView transitionFromView:sourceVC.view toView:destinationVC.view duration:.5 options:0 completion:^(BOOL finished) {
[sourceVC.navigationController pushViewController:destinationVC animated:NO];
}];
The -pushViewController:animated: should not be putted in the animation block but the completion block.
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 calling turnView method who must get dissapear menuView (current) and may display adjustView. When method is called, it is executed with no errors but it does not switch views, menuView keeps and it returns to following line of method call. How to solve it? Thanks
call from menuView:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
aboutTabController * myObject = [[aboutTabController alloc] init];
if (indexPath.section == 1) {
switch (indexPath.row) {
case 0:
[myObject turnView];
break;
case 1:
//
break;
default:
break;}
}
}
method implemented on controller, menuController was defined for menuView class:
- (void) turnView
{
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
if (self.adjustController == nil)
{
adjustView *aController = [[adjustView alloc] initWithNibName:#"adjustView" bundle:nil];
self.adjustController = aController;
[aController release];
}
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self.menuController viewWillDisappear:YES];
[self.adjustController viewWillAppear:YES];
[self.menuController.view removeFromSuperview];
[self.view insertSubview:adjustController.view atIndex:0];
[self.menuController viewDidDisappear:YES];
[self.adjustController viewDidAppear:YES];
[UIView commitAnimations];
}
There are some major conceptual problems in your code, let me try to address them one by one:
Logic in didSelectRowAtIndexPath:
You are creating a new view controller no matter which row is being selected. You should only create it when you need it. Also you if and switch statements are very convoluted and difficult to read.
Calling delegate methods
The methods viewWillAppear: viewDidDisappear: etc. are there for you to catch these events, not to call them yourself. This might make sense in some cases, but they will have absolutely no effect in your animation block.
Animation with blocks, or using built-in animations
You should do your animation with the new block syntax. However, for just flipping to the next view, you can use an official API from Apple without having to program your own animation.
Thus,
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section==1 && indexPath.row==0) {
adjustView *aController = [[adjustView alloc] initWithNibName:#"adjustView" bundle:nil];
aController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:aController animated:YES];
[aController release];
}
}
You can get rid of the controller by calling [self dismissModalViewControllerAnimated:YES] and the animation will automatically be in the other direction.
I am calling a method contained on a controller class that have to change views. It generates an error on insertsubview.view. How to solve it? Thank you
call from current menuViewController class:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
aboutTabController * myObject = [[aboutTabController alloc] init];
if (indexPath.section == 1) {
switch (indexPath.row) {
case 0:
[myObject turnIdioma];
break;
case 1:
//
break;
default:
break;}
}
}
//method implememented in controller class:
- (void) turnIdioma
{
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
if (self.controladorAjustes == nil)
{
settingsViewController *aController = [[settingsViewController alloc] initWithNibName:#"mailViewController" bundle:nil];
self.controladorAjustes = aController;
[aController release];
}
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self.controladorMenu viewWillDisappear:YES];
[self.controladorAjustes viewWillAppear:YES];
[self.controladorMenu.view removeFromSuperview];
[self.view insertSubview:controladorAjustes.view atIndex:0];
[self.controladorMenu viewDidDisappear:YES];
[self.controladorAjustes viewDidAppear:YES];
[UIView commitAnimations];
}
You cannot insert a nil valued object as a subview. Typically the view controller will make sure it is created when you try to get its view property, using the appropriate method depending on whether it is a view defined by a NIB file or not.
IF you are doing something to explicitly set the view to nil then you are probably not taking the right approach. I suspect you are doing something fishy inside your call to:
[self.controladorAjustes viewWillAppear:YES];