首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自UITableView的动画UITableView

来自UITableView的动画UITableView
EN

Stack Overflow用户
提问于 2013-05-18 10:25:57
回答 4查看 1K关注 0票数 1

我有一个桌子视图和一个图像视图,每个视图占屏幕的一半。当用户在图像视图上滑动和选择表格单元格时,我正在尝试动画图像视图。

我使用以下代码:

代码语言:javascript
复制
@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类实例调用它时,它工作得很好,但当我从类实例调用它时,它就不工作了!

代码语言:javascript
复制
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   [self ShowAnimation:_ImageGalaryPreview];
}

,有人能告诉我为什么吗?!

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-05-18 10:37:38

使用您的调用方法,如下所示,它肯定会工作。

代码语言:javascript
复制
-(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];
  }
票数 1
EN

Stack Overflow用户

发布于 2013-05-18 10:35:15

您只需要传递tableview的视图而不是imageView....check,它就能工作了。尽情享受

代码语言:javascript
复制
- (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];
}
票数 0
EN

Stack Overflow用户

发布于 2013-05-18 10:55:19

当用户点击表行时什么都不会发生,因为didSelectRowAtIndexPath方法中的任何行都不包含与didSelectRowAtIndexPath相关的任何内容。也许,试试下面这样的方法。

代码语言:javascript
复制
@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有什么关系。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16623208

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档