Reputation: 1283
UISegmentedControl has a method:
- (void)insertSegmentWithTitle:(NSString *)title atIndex:(NSUInteger)segment animated:(BOOL)animated
If I set the animated to true, is there a way for me to find out when the animation is completed(i.e. completion handler, animation delegate, duration)?
Upvotes: 0
Views: 296
Reputation: 11839
Some time back I also faced this kind to problem to check animation complete of UITableView
, I have found one very useful post - Animation End Check
You can also use this approach for your use, Before posting this answer I have checked this on segment control and it is working well. You might use like -
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *itemArray = [NSArray arrayWithObjects: @"One", @"Two", @"Three", nil];
self.segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
self.segmentedControl.frame = CGRectMake(10, 100, 250, 50);
self.segmentedControl.selectedSegmentIndex = 0;
[self.view addSubview:self.segmentedControl];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[CATransaction begin];
[CATransaction setCompletionBlock:^{
NSLog(@"Animation finished");
}];
[self.segmentedControl insertSegmentWithTitle:@"Four" atIndex:3 animated:YES];
[CATransaction commit];
}
This works as the default animations use CALayer
animations and here we define one implicit CATransaction
.
Upvotes: 2