Domanda

I would like to rotate an UIImageView by 90 degrees over the span of the length of the iPhone's view using imageView.transform = CGAffineTransformMakeRotation(degrees * M_PI/180);, and was wondering how I could implement this as the view is being dragged left by the user (and thus also the ability to rotate "back" if the view is dragged right). Thanks!

enter image description here

È stato utile?

Soluzione

Regarding moving the view, you can do so by updating its frame property like this.-

view.frame = CGRectMake(view.frame.origin.x + xOffset, view.frame.origin.y, view.frame.size.width, view.frame.size.height);

You may also add and observer that listens to your view frame changes.-

[view addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionOld context:NULL];

Here, you basically are asking for receiving a notification whenever the property frame of object view changes. You can handle that notification implementing the following method.-

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    if([keyPath isEqualToString:@"frame"]) {
        // Change object rotation depending on frame.origin.x
    }
}

You'll have to do some maths to calculate rotation based on x position. Also, I guess rotating the view along its center is a little tricky, maybe you'll find the post below useful.-

http://www.informit.com/blogs/blog.aspx?uk=Ask-Big-Nerd-Ranch-Rotating-an-iPhone-View-Around-a-Point

The thing is, you won't have to worry about wherever you're panning to, as view rotation will just get update according to its position everytime it changes.

Hope it helps :)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top