iOS 点击tabBarItem刷新数据并旋转图标

//监听tabBar点击
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    //xjy:二次点资讯刷新数据
    if ([lastItemTitle isEqualToString:@"资讯"] && [item.title isEqualToString:@"资讯"]) {
        
       //用通知刷新数据
        POST_NOTIFICATION(kNotificationNewsRefresh);
    
        if (tabBar.subviews.count >= 3) {
            //这里取的是第一个tabBarButton
            UIView *tabbar = [tabBar.subviews objectAtIndex:2];
            
            for (UIView * view in tabbar.subviews) {
                NSLog(@"xj:%@",[view class]);
                
                if ([view isKindOfClass:NSClassFromString(@"UITabBarSwappableImageView")]) {
                    
                    CABasicAnimation * rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; //让其在z轴旋转
                    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];//旋转角度
                    rotationAnimation.duration = 1; //旋转周期
                    rotationAnimation.cumulative = YES;//旋转累加角度
                    rotationAnimation.repeatCount = 2;//旋转次数
                    [view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
                }
            }
        }
        
        
        
    }
    lastItemTitle = item.title;
}

你可能感兴趣的:(iOS 点击tabBarItem刷新数据并旋转图标)