iphone - How can I transform a UIView from being parallel to the ground to being perpendicular? -


i want transform view plane parallel ground plane perpendicular ground.

any ideas?

to rotate view in 3d, need modify transform property of view's layer.

it sounds want rotate view around x axis. , guess want perspective, edge closer viewer appears larger , edge farther viewer appears smaller.

we'll write helper function makes transform. start identity transform:

static catransform3d transformwithangle(cgfloat angle) {     catransform3d transform = catransform3didentity; 

then set m34 component of transform based on distance viewer view:

    transform.m34 = -1.0f / 300.0f; 

if use number larger 300, perspective weaker. if use number smaller 300, perspective stronger.

next, add rotation:

    transform = catransform3drotate(transform, angle, 1, 0, 0); 

then return transform:

    return transform; } 

let's want apply view named self.riseview. want rotation around bottom edge of view, set layer's anchor point bottom edge:

- (void)viewdidload {     cgrect frame = self.riseview.frame;     self.riseview.layer.anchorpoint = cgpointmake(0.5f, 1.0f);     self.riseview.frame = frame; 

and initialize layer's transform angle of 0:

    self.riseview.layer.transform = transformwithangle(0); } 

you can make view “set” (rotate down ground plane) rotating angle of -m_pi_2:

- (ibaction)setbuttonwastapped:(id)sender {     [self animateriseviewtoangle:-m_pi_2]; } 

and can make “rise” (rotate up) rotating angle of zero:

- (ibaction)risebuttonwastapped:(id)sender {     [self animateriseviewtoangle:0]; } 

here's how animation:

- (void)animateriseviewtoangle:(cgfloat)angle {     [uiview animatewithduration:2 animations:^{         self.riseview.layer.transform = transformwithangle(angle);     }]; } 

Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -