I have another enhancement request for this (sorry!)
To make this a really polished control, it would be great if there was a way to constrain the cube vertically when it rotates so that the top and bottom corners of the cube stay within the screen bounds as it rotates. This behaviour can be found in apps like Clear and WeatherCube
I tried to implement something like this myself by dynamically changing the z-axis translation and perspective as the cube rotates:
CGFloat compensateX = (M_PI_2 - fabs(angle)) * 100.0;
double halfWidth = self.view.bounds.size.width / 2.0;
CGFloat perspective = kPerspective * (fabs(angle) / M_PI_2);
CATransform3D transform = CATransform3DIdentity;
if (applyPerspective) transform.m34 = perspective;
transform = CATransform3DTranslate(transform, 0, 0, -halfWidth - compensateX);
However, this vertically constrains the cube correctly, but results in the two views making the front-most corner of the cube "splitting apart" as the vertex approaches the centre of the screen. I guess I could try tweaking some more to get it right, but I'm not sure I'm along the right lines with this. Is there a better way?
Maybe @robertmryan has a view on this?
I have another enhancement request for this (sorry!)
To make this a really polished control, it would be great if there was a way to constrain the cube vertically when it rotates so that the top and bottom corners of the cube stay within the screen bounds as it rotates. This behaviour can be found in apps like Clear and WeatherCube
I tried to implement something like this myself by dynamically changing the z-axis translation and perspective as the cube rotates:
However, this vertically constrains the cube correctly, but results in the two views making the front-most corner of the cube "splitting apart" as the vertex approaches the centre of the screen. I guess I could try tweaking some more to get it right, but I'm not sure I'm along the right lines with this. Is there a better way?
Maybe @robertmryan has a view on this?