我在基于标签的应用程序中使用简单的Textview来显示一些文本:)我使用以下代码找出了如何更改动画文本:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self];
// To be a swipe, direction of touch must be horizontal and long enough.
if (fabsf(startTouchPosition.x - currentTouchPosition.x) >= HORIZ_SWIPE_DRAG_MIN &&
fabsf(startTouchPosition.y - currentTouchPosition.y) <= VERT_SWIPE_DRAG_MAX)
{
// It appears to be a swipe.
if (startTouchPosition.x < currentTouchPosition.x){
NSString *string = [[NSString alloc]initWithFormat:@"..."];
self.text = string;
}
else{
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
//[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:[self superview] cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:[self superview] cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
[[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];
[self displayNewText];
}
}
但是现在UIViewAnimationTransition中定义了“幻灯片转换”。我知道分页,但我不想用它。检测水平滑动时是否还有其他可能的水平幻灯片动画?
答案 0 :(得分:0)
我想你差不多了。拦截touchesMoved:withEvent
方法就像在当前代码中一样,并更新UIScrollView对象的可见区域。
答案 1 :(得分:0)
我希望您不必检测您的需求的触摸使用UIScrollView作为UITextView的父视图。
scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0,40, 320,200)]; [scroll setContentSize:CGSizeMake(640, 200)];
或者,如果您想为视图设置动画,则可以使用仿射变换。
[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; someview.transform=CGAffineTransformMakeTranslation(-100, 0); [UIView commitAnimations];