標籤:https 關閉 tps selector click test UI round tar
記錄一個簡單的動畫效果,自己寫的,很簡單,僅做記錄。
附一個demo的:
https://github.com/hgl753951/hglTest.git
代碼如下:
1,準備
BOOL _isOpen; NSMutableArray * _btnArray;
2,具體代碼
-(void)initUI{ _btnArray = [[NSMutableArray alloc]init]; for (int i=0; i<4; i++) { UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.tag = i; btn.frame = CGRectMake(260, 420, 40, 40); [btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"c_setting%d",(i+1)%4]] forState:UIControlStateNormal]; [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; [_btnArray addObject:btn]; }}-(void)btnClick:(UIButton *)btn{ //如果沒有開啟 if (!_isOpen) { //開啟九宮格 for (int i = 0; i < _btnArray.count; i++) { UIButton * myBtn = [_btnArray objectAtIndex:i]; [UIView animateWithDuration:0.3 animations:^{ myBtn.frame = CGRectMake(190+(i%2)*70, 350+70*(i/2), 40, 40); } completion:^(BOOL finished) { [UIView animateWithDuration:0.3 animations:^{ myBtn.frame = CGRectMake(200+(i%2)*60, 360+(i/2)*60, 40, 40); }]; }]; } } else { //關閉九宮格 for (int i = 0; i < _btnArray.count; i++) { UIButton * myBtn = [_btnArray objectAtIndex:i]; [UIView animateWithDuration:0.3 animations:^{ myBtn.frame = CGRectMake(190+(i%2)*70, 350+70*(i/2), 40, 40); } completion:^(BOOL finished) { [UIView animateWithDuration:0.3 animations:^{ myBtn.frame = CGRectMake(260, 420, 40, 40); }]; }]; } } _isOpen = !_isOpen;}
效果如下:
ios開發之--簡單動畫效果的添加