简体   繁体   中英

iPhone - Using NSCoder with subclass of UIImageView

I have created a subclass of UIImageView and I am handling the touches for its objects inside the subclass itself.

Now when the user is about to exit the app I want to save the state of the images. And as there are multiple transforms which might have taken place on the images (I am saving all the transforms in a dictionary), I want to be able to save these objects in applicationWillTerminate.

I am using the encodeWithCoder and initWithCoder methods. The objects are saved and loaded as expected (at least looks like it). But when I print the frame size and origin, I get some absurd values on the console.

Can someone please tell me if the frame is not saved when encodeWithCoder is called and the contents are stored in a file?

Thanks.

Why don't you serialize the UIImageView's frame along with the actual UIImageView? Just add another property in encodeWithCoder and initWithCoder for the frame. This way, you can be sure to have the correct frame if you feel something is off.

Please paste the code where you are logging the values of the UIImageView's frame. I believe you may be casting to the wrong type which will cause your values to be off.

通过使用NSUserDefault的key对象和setobject key方法将Dictionary内容写入plist

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM