You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.3 KiB

//
// CustomAnnotationView.m
// watch
//
// Created by WeiChaoZheng on 2017/11/6.
// Copyright © 2017xTT. All rights reserved.
//
#import "CustomAnnotationView.h"
#import "User.h"
#import "Device.h"
@interface CustomAnnotationView ()
@property (nonatomic,strong) UIImageView* portraitImageView;
@property (nonatomic,strong) UIImageView* backImage;
@end
@implementation CustomAnnotationView
-(void)setImageWithURLString:(NSString*)urlString{
NSString *imageName = @"设备默认头像";
if([cUser.cDevice.sex isEqualToString:@"girl"]){
//
imageName = @"icon_girl_head_portrait_1";
}else{
//
imageName = @"icon_boy_head_portrait_1";
}
[self.portraitImageView sd_setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageNamed:imageName]];
}
-(void)setImageWithString:(NSString*)string{
[self.backImage setImage:[UIImage imageNamed:string]];
self.backImage.contentMode = UIViewContentModeScaleAspectFit;
}
-(void)setRadian:(double)radian{
self.transform = CGAffineTransformRotate(self.transform, radian);
}
-(void)setImage:(UIImage *)image{
[super setImage:image];
//自定义动画
self.transform = CGAffineTransformMakeScale(0.5, 0.5);
// 弹簧动画,参数分别为:时长,延时,弹性(越小弹性越大),初始速度
[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.3 initialSpringVelocity:0.3 options:UIViewAnimationOptionLayoutSubviews animations:^{
self.transform = CGAffineTransformMakeScale(1, 1);
} completion:^(BOOL finished) {
}];
}
-(void)setFrame:(CGRect)frame{
[super setFrame:frame];
self.backImage.frame = CGRectMake(0, 3, frame.size.width, frame.size.height);
self.backImage.contentMode = UIViewContentModeScaleAspectFit;
self.portraitImageView.frame = CGRectMake(4, 5, 32, 32);
// self.portraitImageView.center = CGPointMake(_backImage.center.x, _backImage.center.y-3);
self.portraitImageView.layer.cornerRadius = _portraitImageView.bounds.size.width/2;
self.portraitImageView.layer.masksToBounds = YES;
//自定义动画
self.backImage.transform = CGAffineTransformMakeScale(0.5, 0.5);
// 弹簧动画,参数分别为:时长,延时,弹性(越小弹性越大),初始速度
[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.3 initialSpringVelocity:0.3 options:UIViewAnimationOptionLayoutSubviews animations:^{
self.backImage.transform = CGAffineTransformMakeScale(1, 1);
} completion:^(BOOL finished) {
}];
}
- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if (self)
{
// self.bounds = CGRectMake(0.f, 0.f, kWidth, kHeight);
//
// self.portraitImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kHoriMargin, kVertMargin, kPortraitWidth, kPortraitHeight)];
self.portraitImageView = [UIImageView new];
self.backImage = [UIImageView new];
[_backImage addSubview:_portraitImageView];
[_backImage setImage:[UIImage imageNamed:@"宝贝-无头像"]];
[self addSubview:_backImage];
}
return self;
}
@end