Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

简单的重构 #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SXWaveAnimate/SXWaveView.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@

- (void)setPrecent:(int)precent description:(NSString *)description textColor:(UIColor *)tcolor bgColor:(UIColor *)bColor alpha:(CGFloat)alpha clips:(BOOL)clips;

- (void)setPrecent:(int)precent description:(NSString *)description textColor:(UIColor *)tcolor bgColor:(UIColor *)bColor alpha:(CGFloat)alpha clips:(BOOL)clips endless:(BOOL)endless;


@end
71 changes: 44 additions & 27 deletions SXWaveAnimate/SXWaveView.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ - (instancetype)initWithFrame:(CGRect)frame
UIImageView *rotateImg = [[UIImageView alloc]initWithFrame:frame];
rotateImg.contentMode = UIViewContentModeScaleAspectFit;
rotateImg.image = [UIImage imageNamed:@"fb_rotation.png"];

UIView * leftView = [[UIView alloc]init];

[bgView addSubview:leftView];
leftView.width = bgView.width - W/12.5;
leftView.height = bgView.height - W/12.5;
leftView.centerx = bgView.centerx;
leftView.centery = bgView.centery;


leftView.top = W/25;
[bgView addSubview:rotateImg];
Expand All @@ -52,7 +52,7 @@ - (instancetype)initWithFrame:(CGRect)frame
avgScoreLbl.text = @"56%";
avgScoreLbl.textAlignment = NSTextAlignmentCenter;



UILabel *descriptionLbl = [[UILabel alloc]init];
descriptionLbl.width = W / 2;
Expand Down Expand Up @@ -86,7 +86,7 @@ - (instancetype)initWithFrame:(CGRect)frame

self.bigImg.top = W;
self.bigImg.left = -5*W;

}
return self;
}
Expand Down Expand Up @@ -128,6 +128,11 @@ - (void)setPrecent:(int)precent description:(NSString *)description textColor:(U

}

- (void)setPrecent:(int)precent description:(NSString *)description textColor:(UIColor *)tcolor bgColor:(UIColor *)bColor alpha:(CGFloat)alpha clips:(BOOL)clips endless:(BOOL)endless{
[self setPrecent:precent description:description textColor:tcolor bgColor:bColor alpha:alpha clips:clips];
self.endless = endless;
}

- (void)setClips:(BOOL)clips
{
_clips = clips;
Expand Down Expand Up @@ -178,45 +183,57 @@ - (void)addAnimateWithType:(int)type
transformRoate.repeatCount = self.isEndless == YES ? MAXFLOAT : 2;
[self.rotateImg.layer addAnimation:transformRoate forKey:viewRotationKey];

if (type == 0) {
CGFloat avgScore = self.precent;
[UIView animateWithDuration:4.0 animations:^{
self.bigImg.top = W - ((avgScore/100.0) * W);
CGFloat avgScore = self.precent;

__weak typeof(self)weakSelf = self;
void(^beginAnimation)(NSTimeInterval)= ^(NSTimeInterval animationTime) {

[UIView animateWithDuration:animationTime animations:^{
weakSelf.bigImg.top = W - ((avgScore/100.0) * W);
if (avgScore == 100) {
self.bigImg.top = -20;
weakSelf.bigImg.top = -20;
}
self.bigImg.left = 0;
} completion:^(BOOL finished) {

if (weakSelf.endless) {
CAKeyframeAnimation * moveAction = [CAKeyframeAnimation animationWithKeyPath:@"position.x"];

moveAction.values = [NSArray arrayWithObjects:[NSNumber numberWithFloat:self.bigImg.layer.position.x],[NSNumber numberWithFloat:-2*W],nil];
moveAction.autoreverses = true;
moveAction.duration = 4;
moveAction.repeatCount = MAXFLOAT;
[weakSelf.bigImg.layer addAnimation:moveAction forKey:viewMoveKey];
}

}];
};

if (type == 0) {

beginAnimation(4.0);
}else if (type == 1){
CGFloat avgScore = self.precent;

self.bigImg.top = -20;
self.bigImg.left = -5*W;
[UIView animateWithDuration:4.0 animations:^{
self.bigImg.top = W - ((avgScore/100.0) * W);
if (avgScore == 100) {
self.bigImg.top = -20;
}
self.bigImg.left = 0;
}];
beginAnimation(4.0);

}else if (type == 2){
CGFloat avgScore = self.precent;
[UIView animateWithDuration:2.0 animations:^{
self.bigImg.top = -20;
self.bigImg.left = -3*W;
} completion:^(BOOL finished) {
[UIView animateWithDuration:2.0 animations:^{
self.bigImg.top = W - ((avgScore/100.0) * W);
if (avgScore == 100) {
self.bigImg.top = -20;
}
self.bigImg.left = 0;
}];
beginAnimation(2.0);
}];
}




}

-(void)dealloc{
[self.bigImg.layer removeAnimationForKey:viewRotationKey];

[self.rotateImg.layer removeAnimationForKey:viewRotationKey];
[self.bigImg.layer removeAnimationForKey:viewMoveKey];
}

Expand Down
6 changes: 3 additions & 3 deletions SXWaveAnimate/images/SXWaveCell.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7531" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7520"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
Expand All @@ -11,7 +11,7 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="145"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="43"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="144.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="eYk-7V-q5f" userLabel="左边大View">
Expand Down
2 changes: 1 addition & 1 deletion SXWaveAnimateDemo/SXWaveAnimate/SXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ - (void)viewDidLoad {
SXWaveView *animateView1 = [[SXWaveView alloc]initWithFrame:CGRectMake(0+MARGIN, 100+MARGIN,SIDES, SIDES)];
[self.view addSubview:animateView1];
self.animateView1 = animateView1;
[self.animateView1 setPrecent:self.precent description:@"董铂然" textColor:[UIColor orangeColor] bgColor:COLOR(31, 187, 170, 1) alpha:1 clips:NO];
[self.animateView1 setPrecent:self.precent description:@"董铂然" textColor:[UIColor orangeColor] bgColor:COLOR(31, 187, 170, 1) alpha:1 clips:NO endless:true];
// ------步骤3

SXWaveView *animateView2 = [[SXWaveView alloc]initWithFrame:CGRectMake(0+MARGIN*2+SIDES, 100+MARGIN,SIDES, SIDES)];
Expand Down