我刚刚创建了一个新的基于视图的应用程序项目,并将这段代码放在 viewController 的 viewDidLoad 中以获取显示的屏幕。它显示了您需要做什么的理论。需要注意的要点是'clipsToBounds = true'和textFrameRight的负x位置。
- (void)viewDidLoad
{
[超级视图DidLoad];
NSString* text = @"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariaatur
UIFont* font = [UIFont fontWithName:@"Helvetica" size:20.0f];
CGRect textFrameLeft = CGRectMake(0, 0, 320, 480);
UITextView* textLeft = [[UITextView alloc] initWithFrame:textFrameLeft];
textLeft.text = 文本;
textLeft.font = 字体;
textLeft.textColor = [UIColor blackColor];
CGRect textFrameRight = textFrameLeft;
textFrameRight.origin.x -= textFrameRight.size.width/2;
UITextView* textRight = [[UITextView alloc] initWithFrame:textFrameRight];
textRight.text = 文本;
textRight.font = 字体;
textRight.textColor = [UIColor redColor];
CGRect leftFrame = self.view.frame;
leftFrame.size.width /= 2;
UIView* leftView = [[UIView alloc] initWithFrame:leftFrame];
leftView.clipsToBounds = true;
CGRect rightFrame = self.view.frame;
rightFrame.size.width -= leftFrame.size.width;
rightFrame.origin.x += leftFrame.size.width;
UIView* rightView = [[UIView alloc] initWithFrame:rightFrame];
rightView.clipsToBounds = true;
[self.view addSubview:leftView];
[leftView addSubview:textLeft];
[self.view addSubview:rightView];
[rightView addSubview:textRight];
[左视图发布];
[文本左释放];
[右视图发布];
[textRight 释放];
}
===================================
意识到 OP 想要这个动画;这是上述方法的修订版。这个版本有更多的硬编码值;但它只是一个例子。
- (void)viewDidLoad
{
[超级视图DidLoad];
NSString* text = @"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariaatur
UIFont* font = [UIFont fontWithName:@"Helvetica" size:20.0f];
CGRect leftFrame = CGRectMake(0, 0, 0, 480);
CGRect textFrameLeft = CGRectMake(0, 0, 0, 480);
CGRect rightFrame = CGRectMake(0, 0, 320, 480);
CGRect textFrameRight = CGRectMake(0, 0, 320, 480);
UITextView* textLeft = [[UITextView alloc] initWithFrame:textFrameLeft];
textLeft.text = 文本;
textLeft.font = 字体;
textLeft.textColor = [UIColor redColor];
UITextView* textRight = [[UITextView alloc] initWithFrame:textFrameRight];
textRight.text = 文本;
textRight.font = 字体;
textRight.textColor = [UIColor blackColor];
UIView* leftView = [[UIView alloc] initWithFrame:leftFrame];
leftView.clipsToBounds = true;
UIView* rightView = [[UIView alloc] initWithFrame:rightFrame];
rightView.clipsToBounds = true;
[self.view addSubview:leftView];
[leftView addSubview:textLeft];
[self.view addSubview:rightView];
[rightView addSubview:textRight];
[UIView beginAnimations:@"Hide VisibleView" context:nil];
[UIView setAnimationDuration:3.0];
rightView.frame = CGRectMake(320, 0, 0, 480);
textRight.frame = CGRectMake(-320, 0, 320, 480);
leftView.frame = CGRectMake(0, 0, 320, 480);
textLeft.frame = CGRectMake(0, 0, 320, 480);
[UIView 提交动画];
[左视图发布];
[文本左释放];
[右视图发布];
[textRight 释放];
}