点击更多的时候动画展开更多的按钮,包括动画
1.h 文件
#import
#import "Define.h"
@interface DRSDetailMoreSelView : UIView
-(id)initWithFrame:(CGRect)frame withFromeWhere:(NSString *)mstr;
@property (nonatomic, strong) UIView *backImageView;
@property (nonatomic, strong) UIView *mViewMain;
@property (nonatomic, copy) dispatch_block_t leftBlock;
@property (nonatomic, copy) dispatch_block_t rightBlock;
@property (nonatomic, copy) dispatch_block_t ShareBlock;
@property (nonatomic, copy) dispatch_block_t dismissBlock;
-(void)removeFrome;
- (void)show;
- (void)dismissAlert;
@end
2.m文件
-(id)initWithFrame:(CGRect)frame withFromeWhere:(NSString *)mstr{
self = [super initWithFrame:frame];
if (self) {
UIView *mViewMain = [self addView:CGRectMake(Screen_width-150, 54, 150, 100) withBackGroundColor:[UIColor clearColor]];
[self addSubview:mViewMain];
_mViewMain = mViewMain;
[self setDefaultAnchorPointforView:mViewMain];
UISwipeGestureRecognizer *oneFingerSwipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tapImagePhoto:)];
[oneFingerSwipeUp
setDirection:UISwipeGestureRecognizerDirectionUp];
[self addGestureRecognizer:oneFingerSwipeUp];
UISwipeGestureRecognizer *oneFingerSwipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tapImagePhotoRight:)];
[oneFingerSwipeRight
setDirection:UISwipeGestureRecognizerDirectionRight];
[self addGestureRecognizer:oneFingerSwipeRight];
UITapGestureRecognizer *mtapPhoto = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImagePhotoClick:) ];
[self addGestureRecognizer:mtapPhoto];
UIImageView * mimageView = [self addImageView:CGRectMake(0, 0, 150, 100) withImageStr:@"shoppingGoods"];
[mViewMain addSubview:mimageView];
if ([mstr isEqualToString:@"WebView"]) {
_mViewMain.frame = CGRectMake(Screen_width-150, 54, 150, 140);
mimageView.frame=CGRectMake(0, 0, 150, 140);
mimageView.image=[UIImage imageNamed:@"ShareThree"];
}
UIButton * mbtnGo = [self addButtton:CGRectMake(0, 10, 150, 45) title:@"" action:@selector(GoShoopingCart) tag:0];
[mimageView addSubview:mbtnGo];
UIButton * mbtnGoHome = [self addButtton:CGRectMake(0, 55, 150, 45) title:@"" action:@selector(GoHome) tag:0];
[mimageView addSubview:mbtnGoHome];
if ([mstr isEqualToString:@"WebView"]) {
UIButton * mbtnGoShare = [self addButtton:CGRectMake(0, 100, 150, 45) title:@"" action:@selector(GoShare:) tag:1];
[mimageView addSubview:mbtnGoShare];
}
_mViewMain.transform = CGAffineTransformMakeScale(0.01, 0.01);
// 动画
[UIView animateWithDuration:0.2 animations:^{
_mViewMain.transform = CGAffineTransformMakeScale(1.01, 1.01);
} completion:^(BOOL finished) {
_mViewMain.transform = CGAffineTransformMakeScale(1.00, 1.00);
}];
}
return self;
}
// 以某一点缩放
- (void)setDefaultAnchorPointforView:(UIView *)view
{
[self setAnchorPoint:CGPointMake(0.85f, 0.00f) forView:view];
}
- (void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view
{
CGPoint oldOrigin = view.frame.origin;
view.layer.anchorPoint = anchorPoint;
CGPoint newOrigin = view.frame.origin;
CGPoint transition;
transition.x = newOrigin.x - oldOrigin.x;
transition.y = newOrigin.y - oldOrigin.y;
view.center = CGPointMake (view.center.x - transition.x, view.center.y - transition.y);
}
-(void)tapImagePhoto:(UISwipeGestureRecognizer *)tap{
[self dismissAlertAnimation];
}
-(void)tapImagePhotoRight:(UISwipeGestureRecognizer *)tap{
[self dismissAlertAnimation];
}
-(void)tapImagePhotoClick:(UITapGestureRecognizer *)tap{
[self dismissAlertAnimation];
}
-(void)dismissAlertAnimation{
// 动画
[UIView animateWithDuration:0.3 animations:^{
_mViewMain.transform = CGAffineTransformMakeScale(0.2, 0.2);
} completion:^(BOOL finished) {
_mViewMain.transform = CGAffineTransformMakeScale(0.0, 0.0);
[self removeFromSuperview];
}];
if (self.dismissBlock) {
self.dismissBlock();
}
}
-(void)GoShare:(UIButton *)btn{
if (self.ShareBlock) {
self.ShareBlock();
}
[self removeFromSuperview];
}
-(void)GoShoopingCart{
if (self.leftBlock) {
self.leftBlock();
}
[self removeFromSuperview];
}
-(void)GoHome{
if (self.rightBlock) {
self.rightBlock();
}
[self removeFromSuperview];
}
-(void)removeFrome{
[self removeFromSuperview];
}
- (void)show
{
UIViewController *topVC = [self appRootViewController];
[topVC.view addSubview:self];
}
- (void)dismissAlert
{
// 动画
[UIView animateWithDuration:0.3 animations:^{
_mViewMain.transform = CGAffineTransformMakeScale(0.2, 0.2);
} completion:^(BOOL finished) {
_mViewMain.transform = CGAffineTransformMakeScale(0.0, 0.0);
}];
[self removeFromSuperview];
}
- (UIViewController *)appRootViewController
{
UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *topVC = appRootVC;
while (topVC.presentedViewController) {
topVC = topVC.presentedViewController;
}
return topVC;
}
- (void)removeFromSuperview
{
[self.backImageView removeFromSuperview];
self.backImageView = nil;
[super removeFromSuperview];
}
- (void)willMoveToSuperview:(UIView *)newSuperview
{
if (newSuperview == nil) {
return;
}
UIViewController *topVC = [self appRootViewController];
if (!self.backImageView) {
self.backImageView = [[UIView alloc] initWithFrame:topVC.view.bounds];
self.backImageView.backgroundColor = [UIColor whiteColor];
self.backImageView.alpha = 0.0f;
self.backImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
}
[topVC.view addSubview:self.backImageView];
}