我有一个桌子视图和一个图像视图,每个视图占屏幕的一半。当用户在图像视图上滑动和选择表格单元格时,我正在尝试动画图像视图。
我使用以下代码:
@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];
},有人能告诉我为什么吗?!
发布于 2013-05-18 10:37:38
使用您的调用方法,如下所示,它肯定会工作。
-(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];
}发布于 2013-05-18 10:35:15
您只需要传递tableview的视图而不是imageView....check,它就能工作了。尽情享受
- (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];
}发布于 2013-05-18 10:55:19
当用户点击表行时什么都不会发生,因为didSelectRowAtIndexPath方法中的任何行都不包含与didSelectRowAtIndexPath相关的任何内容。也许,试试下面这样的方法。
@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有什么关系。
https://stackoverflow.com/questions/16623208
复制相似问题