Iphone 来自UITableView的动画UIView

Iphone 来自UITableView的动画UIView,iphone,ios,objective-c,uitableview,uiviewanimation,Iphone,Ios,Objective C,Uitableview,Uiviewanimation,我有一个表视图和一个图像视图,每个视图占据屏幕的一半。 当用户在imageview上滑动并且选中表格单元格时,我尝试设置图像视图的动画 我使用以下代码: @interface X() @property (strong, nonatomic) IBOutlet UIImageView *ImagePreview; @property (strong, nonatomic) IBOutlet UITableView *table; @end @implementation X - (void)h

我有一个表视图和一个图像视图,每个视图占据屏幕的一半。 当用户在imageview上滑动并且选中表格单元格时,我尝试设置图像视图的动画

我使用以下代码:

@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
当我在刷卡后调用它时,它工作正常,但当我从
UITableView
类实例调用它时,它不工作

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   [self ShowAnimation:_ImageGalaryPreview];
}

有人能告诉我为什么吗

您只需传递tableview的视图而不是imageView…检查它是否工作。。享受

- (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];
}

您只需要传递tableview的视图而不是imageView…检查它是否工作。。享受

- (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];
}

使用下面给出的调用方法,它肯定会起作用

-(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];
  }

使用下面给出的调用方法,它肯定会起作用

-(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];
  }

当用户点击表行时,不会发生任何事情,因为didselectRowatineXpath方法中的任何行都不包含与indexPath.row相关的内容。也许,试试下面的方法

@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;
}

不过,我不知道您的代码与UIImageView有什么关系。

当用户点击表行时,不会发生任何事情,因为didSelectRowatineXpath方法中没有一行包含任何与indexPath.row相关的内容。也许,试试下面的方法

@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;
}

不过,我不知道你的代码与UIImageView有什么关系。

谢谢你的回复,我也用这段代码解决了这个问题

    [self performSelectorOnMainThread:@selector(stuff) withObject:nil waitUntilDone:NO];

感谢@Hercules:)

感谢您的回复,我也用这段代码解决了这个问题

    [self performSelectorOnMainThread:@selector(stuff) withObject:nil waitUntilDone:NO];


感谢@Hercules:)

您指的是哪种方法?第一段代码位于何处?您如何调用第一段代码?它是否位于某个方法中?那么你是如何调用这个方法的呢?我看不出当didSelectRowAtIndexPath方法中没有选定行时调用这些行代码的意义。我不明白你的意思,这些代码是用来设置视图动画的,这是苹果公司写的,不是我写的。你指的是哪种方法?第一段代码在哪里?你怎么称呼第一段代码?它是否位于某个方法中?那么你是如何调用这个方法的呢?我不认为你调用didSelectRowAtIndexPath方法中的代码行有什么意义,因为它们不在选定的行中。我不明白你的意思,这个代码是用来制作视图动画的,它是苹果公司写的,不是我写的。我不想制作表格动画,我想在您放置imageView的表外设置imageView的动画?在主视图中,我有一个表视图和一个图像视图,每个视图占屏幕的一半确定表示您想在单击tablecell时设置imageView的动画。对吗?确定使用相同的代码&代替tableview传递imageview在imageview中放置一个图像以查看效果…我不想为表格设置动画,我想为您放置imageview的表格外部的imageview设置动画?在主视图中,我有一个表格视图和一个图像视图,每个视图占屏幕的一半确定表示您想在单击tablecell时为imageview设置动画。对吗?确定使用相同的代码&代替tableview传递imageview在imageview中放置一个图像以查看效果…您最好从基础开始。您最好从基础开始。谢谢,在同一类中设置两个视图的控制器后,它工作了谢谢,在同一类中设置两个视图的控制器后,它工作了