簡體   English   中英

來自UITableView的動畫UIView

[英]Animation UIView from UITableView

我有一個表格視圖和一個圖像視圖,每個占據一半的屏幕。 當用戶在imageview上滑動並且選擇了表格單元格時,我正在嘗試為image view設置動畫。

我使用以下代碼:

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

誰能告訴我為什么?

使用下面給出的調用方法,它肯定會工作。

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

您只需要通過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];
}

用戶點擊表行時沒有任何反應,因為didSelectRowAtIndexPath方法中沒有任何行包含與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 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM