0

How can I rotate UIImageViews after time, even if the app has been closed?

I want imageview1 to be rotated 90 degrees every day, imageview2 to be rotated 90 degrees every week and imageview3 to be rotated 90 degrees every month

Example:
If I open my app after 6 days I want imageview1 to be rotated 540 degrees.

Randika Vishman
  • 7,983
  • 3
  • 57
  • 80
  • 2
    have you tried anything? Save the date of the initial app open, calculate the day / week / month difference, rotate the images - where is the problem? – luk2302 Jun 28 '15 at 19:54
  • How do i type this kind of code? i Haven't worked with dates before – user3734699 Jun 28 '15 at 20:10

1 Answers1

2

You need to store the start of the time period somewhere. A very good place for that is NSUserDefaults (tons of tutorials out there on how to store and retrieve data).

Then you need to read that data and calculate the difference in days / weeks (basically 7 days) / months between the stored date and the current date: Days / Weeks1 - Days / Weeks2 - Months

The next step is to actually rotate the image views. That can be achieved by setting the transform property (be aware of radians vs degree):

imageView.transform = CGAffineTransformMakeRotation(numberOfDays * M_PI / 2)

If you try all that together and encounter a serious problem that has not been asked and answered on SO already, feel free to ask another question.

Community
  • 1
  • 1
luk2302
  • 55,258
  • 23
  • 97
  • 137