ios - Animating a UIView in a .xib file -


i've made program in xcode tells time. want have rectangle animates/grows longer seconds increase (time progresses), , starts again when seconds reach 60 (and go 0). don't have storyboarding , have started don't want go , start again.

should use uiview instance , animate 'frame' property?

here clock code:

- (void)viewdidload { [self updatetime];  [super viewdidload];  hourformatter = [[nsdateformatter alloc] init]; hourformatter.dateformat = @"hh"; minuteformatter = [[nsdateformatter alloc] init]; minuteformatter.dateformat = @"mm"; secondformatter = [[nsdateformatter alloc] init]; secondformatter.dateformat = @"ss";     }  - (void)updatetime {  [updatetimer invalidate]; updatetimer = nil;  currenttime = [nsdate date]; nsdateformatter *timeformatter = [[nsdateformatter alloc] init]; [timeformatter settimestyle:nsdateformattermediumstyle];  hourlabel.text = [hourformatter stringfromdate: currenttime]; minutelabel.text = [minuteformatter stringfromdate: currenttime]; secondlabel.text = [secondformatter stringfromdate: currenttime];  updatetimer = [nstimer scheduledtimerwithtimeinterval:0.01 target:self selector:@selector(updatetime) userinfo:nil repeats:yes]; } 

yes, can use uiview , animate frame.

you shouldn't using timer though, set animation run full duration , complete frame height change , use timer restart next animation. give smoothest animation.

for updating time display need timer running once per second.

look @ running animation this:

cgrect frame = self.expandingtimeview.frame; frame.height = 0; self.expandingtimeview.frame = frame;  [uiview animatewithduration:60                  animations:^{     frame.height = max_frame_height;     self.expandingtimeview.frame = frame; }]; 

there's guide here.

this code go in updatetime method, i'm assuming called each minute timer. need correct name of expandingtimeview whatever view property called, , need replace max_frame_height maximum height view should grow during animation.

you may want have 2 methods, 1 containing view animation (updatetimeview), called each minute , 1 containing label text update (updatetimelabels), called each second. in case 2 timers should created in viewwillappear:


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -