斜杠运动

172 阅读1分钟
#import "ViewController.h"

@interface ViewController ()

@property (strong, nonatomic) UIView *indicatorLine;
@property (strong, nonatomic) NSTimer *timer;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor lightGrayColor];
    _indicatorLine = UIView.new;
    _indicatorLine.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.7];
    _indicatorLine.frame = CGRectMake(40, 200, 3, 50);
    [self.view addSubview:_indicatorLine];

    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(runTest) userInfo:nil repeats:YES];
    [self.timer fire];
}

- (void)runTest {
    [UIView animateWithDuration:0.25 delay:.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
        CGRect frame = self.indicatorLine.frame;
        frame.origin.x += 3;
        self.indicatorLine.frame = frame;
    } completion:nil];
}
@end

Simulator Screen Shot - iPhone 13 Pro Max - 2022-05-10 at 15.58.50.png