iOS動畫 對號和叉叉
阿新 • • 發佈:2018-11-01
很方便的呼叫方法:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.checkView = [[SHCheckInfoView alloc] initWithFrame:CGRectMake(0, 0, 40, 40) lineWidth:2 lineColor:[UIColor redColor]];
self.checkView.center = self.view.center;
[self.view addSubview:self.checkView];
}
- (IBAction)onRightBtnAction:(id)sender {
[self.checkView showAnimationWithState:XYProgressResult_Success duration:1.5 complete:nil];
}
- (IBAction)onFailedBtnAction:(id)sender {
[self.checkView showAnimationWithState:XYProgressResult_Failed duration:1.5 complete:nil];
}
SHCheckInfoView標頭檔案介面:
#import <UIKit/UIKit.h>
// 設定動畫效果樣式
typedef enum{
XYProgressResult_Success,
XYProgressResult_Failed,
}XYProgressResultState;
@interface SHCheckInfoView : UIView
// 線條寬度,預設為3.0;
@property (nonatomic, assign) CGFloat lineWidth;
// 線條顏色,預設是redColor
@property (nonatomic, strong) UIColor *lineColor;
// 設定填充顏色,預設是clearColor;
@property (nonatomic, strong) UIColor *fillColor;
- (instancetype)initWithFrame:(CGRect)frame lineWidth:(CGFloat)lineWidth lineColor:(UIColor *)lineColor;
/*
* state 成功或者失敗狀態,決定繪畫樣式。
* duration 動畫時長。
* complate 動畫結束時回撥。
*/
- (void)showAnimationWithState:(XYProgressResultState)state duration:(NSTimeInterval)duration complete:(void (^) (BOOL isFinish))complate;
@end
程式碼GitHub地址:https://github.com/lvshaohua/SHCheckInfoView