Objective-C“星球大战”开场爬行

时间:2013-03-19 13:37:19

标签: iphone ios objective-c ipad

如何为iOS打开“星球大战”? 我尝试在CSS3(3D变换)上做,但它很慢。 是否可以在Objective-C上进行?

请说明如何用Objective-C写作!

1 个答案:

答案 0 :(得分: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];

到达那里!

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

// 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];