-13

如何为 iOS 做《星球大战》开场抓取?我尝试在 CSS3(3D 变换)上做,但速度很慢。是否可以在 Objective-C 上做到这一点?

请展示如何用 Objective-C 编写代码!

4

1 回答 1

15

在 Objective-C 中是可能的。

只因为我好

我们将从一个简单的旋转开始,看看会发生什么。如果你构建,你会看到我们有一个很好的旋转,但它看起来并不现实。我们也需要倾斜视角才能获得真正的效果。

UITextView *textView = [[UITextView alloc] initWithFrame:self.view.bounds];
[textView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
[textView setBackgroundColor:[UIColor blueColor]];

[textView setText:@"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."];

[textView setFont:[UIFont boldSystemFontOfSize:32.0]];
[textView setTextAlignment:NSTextAlignmentCenter];

// Rotate the text
[textView.layer setTransform:CATransform3DMakeRotation(M_PI_4, 1.0, 0.0, 0.0)];

// Now we need to skew the box so the bottom is wider than the top.

[self.view addSubview:textView];

到达那里!

好吧,经过一番谷歌搜索,我们已经弄清楚了如何调整 m34 的值CATransform3D来调整我们正在寻找的视角。颜色也选对了!建造它,你会清楚地看到我们要去哪里。但是我们需要调整框架以确保它填满屏幕。然后我们可以添加一些自动滚动动画,这样我们就不必用手指滚动了。

// Learn the basics of matrix transforms: http://markpospesel.wordpress.com/tag/catransform3d/

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectInset(self.view.bounds, 32.0, 32.0)];
[textView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
[textView setBackgroundColor:[UIColor blackColor]];
[textView setTextColor:[UIColor yellowColor]];
[textView setEditable:NO];

[textView setText:@"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."];

[textView setFont:[UIFont boldSystemFontOfSize:36.0]];
[textView setTextAlignment:NSTextAlignmentCenter];

// Start with a blank transform
CATransform3D blankTransform = CATransform3DIdentity;

// Skew the text
blankTransform.m34 = -1.0 / 500.0;

// Rotate the text
blankTransform = CATransform3DRotate(blankTransform, 45.0f * M_PI / 180.0f, 1.0f, 0.0f, 0.0f);

// Set the transform
[textView.layer setTransform:blankTransform];

[self.view addSubview:textView];
于 2013-03-19T13:41:46.057 回答