以下是我的ClickableSpan.java和TouchableSpan.java代码:
然后,我让LinkTouchMovementMethod类继承LinkMovementMethod类;onTouchEvent()方法中,onClick变成了onTouch:
然后,在你的MovementMethod中做适当的更改:
TabPage1 *firstViewControlle = [[TabPage1 alloc] init]; UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController: firstViewControlle]; UITabBarItem *time = [[UITabBarItem alloc] initWithTitle: @"First" image: nil tag: 0]; time.image = [UIImage imageNamed:@""]; nav1.tabBarItem = time; TabPage2 *secondViewController = [[TabPage2 alloc] init]; UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController: secondViewController]; UITabBarItem *time2 = [[UITabBarItem alloc] initWithTitle: @"second" image: nil tag: 1]; nav2.tabBarItem = time2; UITabBarController *tabBarController = [[UITabBarController alloc] init]; NSArray *array = [NSArray arrayWithObjects: nav1,nav2, nil]; tabBarController.viewControllers = array; [self presentViewController:tabBarController animated:YES completion:nil]; ///////////在TabPage1中 self.navigationitem.title = @"111";
-(void)loadView
{
self.view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];
self.view.backgroundColor = [UIColor redColor];
imageV = [[UIImageView alloc]initWithFrame:CGRectMake(70, 150, 200, 200)];
imageV.backgroundColor = [UIColor blueColor];
[self.view addSubview:imageV];
[imageV release];
NSArray *arr = [NSArray arrayWithObjects:@"轻拍",@"长按",@"旋转",@"捏合",@"轻扫",@"拖拽", nil];
UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:arr];
[seg addTarget:self action:@selector(tap:) forControlEvents:UIControlEventValueChanged];
seg.frame = CGRectMake(0, 400, 320, 40);
imageV.userInteractionEnabled = YES;
[self.view addSubview:seg];
}
-(void)tap:(UISegmentedControl *)tap
{
for(id gesture in imageV.gestureRecognizers)
{
[imageV removeGestureRecognizer:gesture];
}
switch (tap.selectedSegmentIndex)
{
case 0:
{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dotap:)];
[imageV addGestureRecognizer:tap];
imageV.userInteractionEnabled = YES;
[tap release];
break;
}
case 1:
{
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
[imageV addGestureRecognizer:longPress];
[longPress release];
break;
}
case 2:
{
UIRotationGestureRecognizer *rotationPress = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationPress:)];
[imageV addGestureRecognizer:rotationPress];
[rotationPress release];
break;
}
case 3:
{
UIPinchGestureRecognizer *pinchPress = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchPress:)];
[imageV addGestureRecognizer:pinchPress];
[pinchPress release];
break;
}
case 4:
{
UISwipeGestureRecognizer *swipePress = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipePress:)];
[imageV addGestureRecognizer:swipePress];
[swipePress release];
UISwipeGestureRecognizer *swipePress1 = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipePress:)];
[imageV addGestureRecognizer:swipePress1];
swipePress.direction = UISwipeGestureRecognizerDirectionLeft ;
[swipePress1 release];
break;
}
case 5:
{
UIPanGestureRecognizer *panPress = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panPress:)];
[imageV addGestureRecognizer:panPress];
[panPress release];
break;
}
default:
break;
}
}
-(void)dotap:(UITapGestureRecognizer *)dotap//轻按随机换图
{
NSString *imageName = [NSString stringWithFormat:@"h%d.jpeg",arc4random()%8+1];
imageV.image = [UIImage imageNamed:imageName];
}
-(void)longPress:(UILongPressGestureRecognizer *)longPress//长按按顺序换图
{
if(longPress.state == UIGestureRecognizerStateEnded)
{
NSString *imageName = [NSString stringWithFormat:@"h%d.jpeg",i%8+1] ;
imageV.image = [UIImage imageNamed:imageName];
i = i+1;
}
}
-(void)rotationPress:(UIRotationGestureRecognizer *)rotationPress//旋转
{
[imageV setTransform:CGAffineTransformMakeRotation(rotationPress.rotation)];
}
-(void)pinchPress:(UIPinchGestureRecognizer *)pinchPress//捏合
{
[imageV setTransform:CGAffineTransformMakeScale(pinchPress.scale, pinchPress.scale)];
}
-(void)swipePress:(UISwipeGestureRecognizer *)swipePress//轻扫
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:(swipePress.direction == UISwipeGestureRecognizerDirectionLeft )?UIViewAnimationTransitionFlipFromLeft:UIViewAnimationTransitionFlipFromRight forView:imageV cache:YES];
[UIView commitAnimations];
}
-(void)panPress:(UIPanGestureRecognizer *)panPress //拖拽
{
CGPoint point =[panPress translationInView:imageV];
imageV.transform = CGAffineTransformMakeTranslation(point.x, point.y);
}