ios - UIView Animate and completion block -



ios - UIView Animate and completion block -

i'm trying animate tableview's offset down, in completion block move up. code not doing in completion block:

-(void)viewdidappear:(bool)animated { if (true) { nslog(@"animating table view"); [uiview animatewithduration:.25 animations:^{ self.tableview.contentoffset = cgpointmake(self.tableview.contentoffset.x, self.tableview.contentoffset.y - 60); } completion:^(bool finished){ nslog(@"completion block"); }]; } }

"completion block" never gets outputted... ideas?

edit:

ok, has uirefreshcontrol:

- (void)viewdidload { [super viewdidload]; if (true) { uirefreshcontrol *refresh = [[uirefreshcontrol alloc] init]; refresh.attributedtitle = [[nsattributedstring alloc] initwithstring:@"pull refresh"]; [refresh addtarget:self action:@selector(refreshtableview:) forcontrolevents:uicontroleventvaluechanged]; [self setrefreshcontrol:refresh]; } }

when refresh controll added, won't fire off completion block. if dont' add together control, works intended.

edit 2:

k, if scroll table view, completion block fired:

2013-02-15 13:37:06.266 [1922:14003] animating table view 2013-02-15 13:37:14.782 [1922:14003] completion block

the code written should log "completion block" right after "animating table view", has 8 sec delay cause thats when scrolled table view myself.

how "pull refresh" looks like:

i able reproduce issue , found workaround.

when using uiscrollview, uitableview inherits from, can't alter contentoffset not animatable property. instead, need utilize method setcontentoffset:animated:.

so, need follows:

set view controller uitableview delegate. did in on viewdidappear. set flag, know in delegate scroll happened because triggered. in delegate method - (void)scrollviewdidendscrollinganimation:(uiscrollview *)scrollview, bounce animation (you here add together delay using performselector:afterdelay:.

here's code:

@interface myviewcontroller () @property (assign, nonatomic) bool shouldreturn; @end @implementation myviewcontroller -(void)viewdidappear:(bool)animated { [super viewdidappear:animated]; if (true) { nslog(@"animating table view"); self.shouldreturn = yes; self.tableview.delegate = self; [self.tableview setcontentoffset: cgpointmake(self.tableview.contentoffset.x, self.tableview.contentoffset.y - 60) animated:yes]; } } - (void)viewdidload { [super viewdidload]; if (true) { uirefreshcontrol *refresh = [[uirefreshcontrol alloc] init]; refresh.attributedtitle = [[nsattributedstring alloc] initwithstring:@"pull refresh"]; [refresh addtarget:self action:@selector(refreshtableview:) forcontrolevents:uicontroleventvaluechanged]; [self setrefreshcontrol:refresh]; } } - (void)scrollviewdidendscrollinganimation:(uiscrollview *)scrollview { if (self.shouldreturn) { self.shouldreturn = no; [self.tableview setcontentoffset:cgpointzero animated:yes]; } } @end

ios objective-c

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -