Rachel Roumeliotis

Rachel Roumeliotis, a Strategic Content Director at O'Reilly Media, Inc., leads an editorial team that covers a wide variety of programming topics ranging from full-stack, to open source in the enterprise, to emerging programming languages. She is a Programming Chair of OSCON and O'Reilly's Software Architecture Conference. She has been working in technical publishing for 10 years, acquiring content in many areas including mobile programming, UX, computer security, and AI.

One of the simplest visual tricks you can do in iOS is to make a part of your UI pretend to be a 3D object. We’ve found that this is an excellent way to add some life and visual interest to both apps and games.

Below, you’ll learn how to make a view rotate in 3D and have a perspective effect.

First, your project needs to use the QuartzCore framework.

Next, when you want the animation to begin, you do this:

1

2

3

4

5

6

7

8

9

10

11

12

CABasicAnimation*animation=[CABasicAnimation

animation WithKeyPath:@"transform.rotation.y"];

animation.fromValue=@(0);

animation.toValue=@(2*M_PI);

animation.repeatCount=INFINITY;

animation.duration=5.0;

[self.rotatingView.layer addAnimation:animation forKey:@"rotation"];

CATransform3D transform=CATransform3DIdentity;

transform.m34=1.0/500.0;

self.rotatingView.layer.transform=transform;

To stop the animation, you do this:

1

[self.rotatingView.layer removeAnimationForKey:@"rotation"];

How It Works

CABasicAnimation allows you to animate a property of a view from one value to another. In the case of rotating a view, the property that we want to animate is its rotation, and the values we want to animate from and to are angles.

When you create the animation using [CABasicAnimation animationWithKeyPath:], you specify the property you want to animate. In this case, the one we want is the rotation around the Y axis.

The animation is then configured. In this example, we made the rotation start from zero, and proceed through to a full circle. In Core Animation, angles are measured in radians, and there are 2 * π radians in a full circle. So, the from value and to value are set thusly:

1

2

animation.fromValue=@(0);

animation.toValue=@(2*M_PI);

Next, the animation is told that it should repeat an infinite number of times, and that the full rotation should take 5 seconds.

1

2

animation.repeatCount=INFINITY;

animation.duration=5.0;

The animation is started by adding the animation to the view’s layer, using the addAnimation:forKey: method. This method takes two parameters: the animation object that you want to use, and a key (or name) that the animation should be referred by.

Don’t be confused by the similarity between the “key” that you use when you add the animation, and the “key path” you use when creating the animation. The former is just a name you give the animation, and can be anything; the “key path” describes exactly what the animation modifies.

1

[self.rotatingView.layer addAnimation:animation forKey:@"rotation"];

The last step to this is to give the rotating view a little perspective. If you run the code while omitting the last few lines, you’ll end up with a view that appears to horizontally squash and stretch. What you want is for the edge that’s approaching the user’s eye to appear to get bigger, while the edge that’s moving away from the user’s eye to get smaller.

This is done by modifying the view’s 3D transform. By default, all views have a transform matrix applied to them that makes them all lie flat over each other. When you want something to have perspective, though, this doesn’t apply, and we need to override it.

1

2

3

CATransform3D transform=CATransform3DIdentity;

transform.m34=1.0/500.0;

self.rotatingView.layer.transform=transform;

The key to this part of the code is the second line: the one where the m34 field of the transform is updated. This part of the transform controls the sharpness of the perspective. (It’s basically how much the z coordinate gets scaled towards or away from the vanishing point as it moves closer to or further from the “camera“.)

As you can see, adding 3D and perspective effects isn’t terribly difficult, but the results can provide an excellent payoff in terms of user immersion.

OSCON 2013 Speaker Series

Paco Nathan (@pacoid) is Director of Data Science at Concurrent, O’Reilly Author, and OSCON 2013 Speaker. In this interview we talk about creating enterprise data workflow with Cascading. Be sure to check out Paco’s book on the subject here

NOTE: If you are interested in attending OSCON to check out Paco’s talk or the many other cool sessions, click over to the OSCON website where you can use the discount code OS13PROG to get 20% your registration fee.

Key highlights include:

Cascading is an abstraction layer on top of Hadoop [Discussed at 0:23]

OSCON 2013 Speaker Series

Henrik Ingo (@h_ingo) is a MySQL architect, author, and OSCON 2013 Speaker. In this interview we talk about high availability in MySQL and why he switched to MongoDB.

NOTE: If you are interested in attending OSCON to check out Henrik’s talk or the many other cool sessions, click over to the OSCON website where you can use the discount code OS13PROG to get 20% your registration fee.

OSCON 2013 Speaker Series

Andy Gup (@agup) is a Developer Evangelist at ESRI and OSCON 2013 Speaker. In this interview we talk about location capabilities in apps as well as location analytics.

NOTE: If you are interested in attending OSCON to check out Andy’s talk or the many other cool sessions, click over to the OSCON website where you can use the discount code OS13PROG to get 20% your registration fee.

Microsoft, Apple, and Google try to define themselves as they become more alike

As I was sitting in the Build keynote I realized that both of the keynotes that I had attended recently (Google I/O and Build—I couldn’t get into WWDC) were really about me—well not just me but us, the consumers. This time it was Microsoft that had the DJ playing tunes as we were treated to images from Windows 8.1 and colored spotlights careened off of every surface (no pun intended) in the subterranean hall at Moscone South. The main thrust of the Build keynote, which started with Steve Ballmer announcing that Microsoft would now enter a time of rapid release for its software, was how well Windows 8 had done and how Windows 8.1 would be even better.

There were big cheers for the return of the Start Button, the ability to boot to desktop, a “refining” and “re-blending” of the massively overhauled Windows OS, all of which I think are great steps forward. In fact, there have been over 800 updates to Windows since November 2012. This already demonstrates that rapid release is the focus at Microsoft. And then there were the devices, so many devices, from Windows Phones to giant desktops that become giant tablets to all-in-ones that convert from laptops to tablets.

OSCON 2013 Speaker Series

Tony Santos, (@tsmuse) is a User Experience Lead at Mozilla and OSCON 2013 Speaker. We talk about Human-Centered Design and how it can make all the difference.

NOTE: If you are interested in attending OSCON to check out Tony’s talk or the many other cool sessions, click over to the OSCON website where you can use the discount code OS13PROG to get 20% your registration fee.

OSCON 2013 Speaker Series

Ed Snajder is a 3D-printer aficionado, DBA at Jive Software and OSCON 2013 speaker. We talk about the ins and outs of the new world of 3D printing (a little sneak preview of what Ed will be speaking about at this year’s OSCON). If you are interested in attending to check out Ed’s talk or the many other cool sessions, click over to the OSCON website where you can use the discount code OS13PROG to get 20% your registration fee.

Tips on Getting Started with Simon Monk

Simon Monk @simonmonk2 is a full-time author who focuses his writing talents on open source hardware topics. He is currently writing the Raspberry Pi Cookbook which will be available in early release in July and in final release in the fall. Recently, I had the opportunity to sit down with Simon and we talked about one of the coolest things in open source hardware today, the Raspberry Pi.

A conversation with the founder of Neo4J, Emil Eifrem

Emil Eifrem @emileifrem is the Founder of Neo4j and CEO of Neo Technology. He is also one of the authors of Graph Databases. Recently, I had the opportunity to sit down with Emil and we talked about the current and future opportunities for graph databases.

Humid, harmonious, and happy

People weren’t kidding when they told me New Orleans is humid, but the good news is the conference venue has great air conditioning. As expected TechEd is focused mainly on system administrator issues, but I’m feeling that even more so this year with BUILD right around the corner on June 26. However, that isn’t keeping the ASP.NET team from letting us in on what they’ve been working on these past few months.

I wrote a post a little more than a year ago on how Microsoft was starting to embrace open source. Well, it seems to be paying off with Web API 2: two of the new features, CORS and Attribute Routing, were initially contributed by community members and then perfected with the ASP.NET team. These two features are making writing code for your website more streamlined.

In other impressive updates, layout and styling are now based in Bootstrap and cross-browser testing is now much quicker with a tool codenamed “Artery.” We saw, Damian Edwards, Program Manager on the ASP.NET team, make a change in the code, rerun the program, and show us the updated website on local versions of Explorer and Chrome. In addition to upgrade announcements, a welcome change came in the form of a consistent toolset offering with Visual Studio 2013 that makes working across Web Forms and MVC much easier for developers. All new versions of these technologies, ASP.NET MVC 5, Web API 2, and Signal R2 will run only with .NET 4.5.

Sitting in the front of the packed room I kept thinking this is what Microsoft needs—an engaged audience that can work with a brilliant team to consistently update the technology and encourage change.

Oh, and Microsoft (in what I think is a smart move) is selling the Surface RT and Surface Pro, to full attendees, at deep, deep discounts, with the RT priced at $99 and the Pro at $399. The lines have been massive since the offer was announced. Hopefully this will provide Microsoft with more mindshare if not market share in the coming months.

And a note about Google Glass: I brought them to the conference in my continued social experiment to see how people would react. It has been a mixed bag of folks wanting to talk to me about them, those afraid I am recording them, and even a few that aren’t sure what it is. It continues to be good conversation starter as is the story of my eating my first crawdad—a New Orleans staple!