Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
As I mentioned in the last thread, I have a race car image view that almost goes around in a circle. For the animation, I am using Core Animation directly. Now that I have done that, I would like to make the image view change its orientation every time its heading is changed. I'm thinking of subclassing UIImageView and overriding its setCenter method so that every time setCenter is called, the app calculates the slope of an imaginary line segment that connects the image view's old center to that of its new center. Using this slope, the image view can then figure out where its corners should be.
 

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
As I mentioned in the last thread, I have a race car image view that almost goes around in a circle. For the animation, I am using Core Animation directly. Now that I have done that, I would like to make the image view change its orientation every time its heading is changed. I'm thinking of subclassing UIImageView and overriding its setCenter method so that every time setCenter is called, the app calculates the slope of an imaginary line segment that connects the image view's old center to that of its new center. Using this slope, the image view can then figure out where its corners should be.

Ok, that didn't work. Evidently, the image view's position property is not updated when its layer moves. I guess I'll have to figure out some other way. I might need to have my view controller do the reorientation.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
Ok, that didn't work. Evidently, the image view's position property is not updated when its layer moves. I guess I'll have to figure out some other way. I might need to have my view controller do the reorientation.

This does sound like logic that belongs in the ViewController.
 

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
I just added the view controller as an observer for the race car image view's layer's presentation layer's bounds. However, I ran the app, but the app was terminated with an error:

Code:
instance 0x7a99c510 of class NSConcreteValue was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x7a98b540> (
<NSKeyValueObservance 0x7a9a3160: Observer: 0x7a993800, Key path: origin, Options: <New: YES, Old: YES, Prior: NO> Context: 0x0, Property: 0x7a993c10>
)
2014-09-19 10:12:20.769 Reading Expressway[1346:64701] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x7a99c510 of class NSConcreteValue was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x7a98b540> (
<NSKeyValueObservance 0x7a9a3160: Observer: 0x7a993800, Key path: origin, Options: <New: YES, Old: YES, Prior: NO> Context: 0x0, Property: 0x7a993c10>
)'
 
Last edited by a moderator:

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Is there a question?

As the error says, you need to remove any KVO observers before the object is dealloced.

However, it says the key path is origin and you said it was something else. Not sure what that means.
 

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
OK, I think I found an alternate route. I can create a CALayer, add my image view's layer to it, adjust the image view's layer's position so that it is relative to the other layer, then makes the former layer rotate.
 

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
I found another way - create a view in Interface Builder, put the image view in that view, tell the app to add the newly created view as a subview, and have the app apply a rotation animation to that view's layer.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.