0

我正在使用 Interface Builder 为 iOS6 编写一个应用程序,它在 UIImageView 顶部的 UITextView 中显示文本(来自文本数组)。用户可以向右或向左滑动以更改数组中的另一个文本。

现在我正在使用以下代码:

    CATransition *transition = [CATransition animation];
    transition.duration = 0.25;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype =kCATransitionFromRight;
    transition.delegate = self;
    [self.view.layer addAnimation:transition forKey:nil];
    [self.view addSubview:self.text];

当用户滑动,UITextView,UIImageView,和所有的时候,整个屏幕都是动画的。当用户滑动但将 UIImageView 留在原位时,如何仅使文本左右移动?

4

2 回答 2

2

使用此动画向左移动:

 [UIView animateWithDuration:1 
                 animations:^{
                     [yourTextView setFrame:CRectMake(-yourTextView.frame.size.width,yourTextView.frame.origin.y,yourTextView.frame.size.width,yourTextView.frame.size.height)];
                 }
                 completion:^(BOOL finished){
                     //do something after completion if needed
                     //new text to uitextView.
                 }];

使用此动画向右移动:

[UIView animateWithDuration:1 
                 animations:^{
                     [yourTextView setFrame:CRectMake(self.view.frame.size.width+yourTextView.frame.size.width,yourTextView.frame.origin.y,yourTextView.frame.size.width,yourTextView.frame.size.height)];
                 }
                 completion:^(BOOL finished){
                     //do something after completion if needed
                     //new text to uitextView.
                 }];
于 2012-12-01T07:14:55.353 回答
1

使用 UITextview 的图层添加动画。[YourTextView.layer addAnimation:transition forKey:nil];

于 2012-12-01T09:49:32.780 回答