Make a simple contact list, you can add delete contacts, and now not add avatar and text, then slowly add
1, how to appear at both ends of Uitoolbar two buttons bar button item
But add a bar button item in the middle of the button, and then set the button's properties identifier to flexible Space
2. Then drag to add event
1 // Add 2 // Delete
3. Implement message response
Click the Add button to add a contact information to the window each time you add it to the last side.
Click the Delete button to delete a contact information from the window and delete the last one each time. Invalidates the Delete button when only the toolbar is left.
Add button
1-(Ibaction) Add: (Uibarbuttonitem *) sender//Add2 {3NSLog (@"%@",@"Add");4 //0. Get the last control5UIView *last =[Self.view.subviews Lastobject];6 //to calculate the position of the control currently being inserted7 //y = The last control's Y + height + spacing of the last control8CGFloat rowy = last.frame.origin.y + last.frame.size.height +1;9 Ten //1. Create OneUIView *view =[[UIView alloc] init]; A //view.frame = CGRectMake (0,rowy,320,50); -View.backgroundcolor =[Uicolor Redcolor]; - the //2. Add - [Self.view Addsubview:view]; - - //3. Delete button is valid +_removeitem.enabled =YES; - +View.frame = CGRectMake ( the, Rowy, the, -); AView.alpha =0; at //4. Performing animations - //Animation Implementation Mode 1 - //[UIView Beginanimations:nil context:nil]; - //[UIView setanimationduration:1.0]; - - //Animation Implementation Mode 2 in //Animate block using UIView method - //[UIView animatewithduration:1.0 animations:^{ to // + // }]; - //Animate block using UIView method the[UIView Animatewithduration:kdur animations:^{ *View.frame = CGRectMake (0, Rowy, the, -); $View.alpha =1;Panax NotoginsengAdd another action after the animation ends -} completion:^(BOOL finished) { theNSLog (@"%@",@"Add Complete"); + }]; A the //[UIView commitanimations]; +}
There are three ways to implement animations:
1. How to implement the animation 1
[UIView Beginanimations:nil Context:nil];
[UIView setanimationduration:1.0];
Animation appears
[UIView commitanimations];
2, [UIView animatewithduration:1.0 animations:^{
Animation changes
}];
3, [UIView Animatewithduration:kdur animations:^{
View.frame = CGRectMake (0, Rowy, 320, 50);
View.alpha = 1;
}//here to implement some other actions at the end of the animation
completion:^ (BOOL finished) {
NSLog (@ "%@", @ "add complete");
}];
Delete button
1 #pragmaMark Deletes a row2-(Ibaction) Remove: (Uibarbuttonitem *) sender//Delete3 {4NSLog (@"%@",@"Remove");5 6 //1. Remove the last child control7UIView *last =[Self.view.subviews Lastobject];8 //Judging whether it's toolbar9 //if ([Last Iskindofclass:[last class]]) return;//Ten[UIView Animatewithduration:kdur animations:^{ OneCGRect temp =Last.frame; ATemp.origin.x = the; -Last.frame = temp;//Change Position -Last.alpha =0;//Change Transparency the} completion:^(BOOL finished) { - //2. Delete child controls - [last Removefromsuperview]; -_removeitem.enabled = self.view.subviews.count! =1; +NSLog (@"%@",@"Remove is complete ."); - }]; + A //3. Determine the number of remaining child controls at //if (Self.view.subviews.count = = 1) - // { - //_removeitem.enabled = NO; - // } - -}
The use of iOS development learning Note 023-uitoolbar