ifish/Ifish/views/LXShareView/LXShareImageVIew.m

290 lines
7.8 KiB
Objective-C

//
// LXShareImageVIew.m
// shreImgAnimition
//
// Created by imac on 16/9/5.
// Copyright © 2016年 xiang. All rights reserved.
//
#import "LXShareImageVIew.h"
#define SHAREVIEW_HEIGHT 160
#define COLOR_MIAN [UIColor colorWithRed:65.0/256.0 green:65.0/256.0 blue:65.0/256.0 alpha:1]
#define kScreenSize [UIScreen mainScreen].bounds.size
@interface LXShareImageVIew (){
//bool displayingPrimary;
NSTimer *timer;
}
@end
@implementation LXShareImageVIew
@synthesize primaryView=_primaryView, scrollView=_scrollView ,spinTime;
-(id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setData];
self.backgroundColor = [UIColor clearColor];
//self.alpha = 0.4;
spinTime = 1.0;
[self setUp];
}
return self;
}
-(void)setData{
self.titles = @[@"微信",@"朋友圈",@"QQ",@"微博"];
self.imges = @[@"ifish_sharewechat",@"ifish_sharecircle",@"ifish_shareqq",@"ifish_shareblog"];
}
//- (void) setPrimaryView:(UIView *)primaryView{
//
// _primaryView = primaryView;
//
// CGRect frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
// [self.primaryView setFrame: frame];
//
// [self roundView: self.primaryView];
// self.primaryView.userInteractionEnabled = YES;
// UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(flipTouched:)];
// gesture.numberOfTapsRequired = 1;
// [self.primaryView addGestureRecognizer:gesture];
//
//}
- (void) roundView: (UIView *) view{
[view.layer setCornerRadius: (self.frame.size.height/2)];
[view.layer setMasksToBounds:YES];
}
-(void)flipTouched:(id)sender
{
// [UIView transitionWithView:self.primaryView duration:spinTime options:UIViewAnimationOptionTransitionFlipFromLeft+UIViewAnimationOptionCurveEaseInOut animations:^{
//
//
// } completion:^(BOOL finished) {
//
//
// }];
}
-(void)setUp{
if (!self.blackOverBack) {
self.blackOverBack = [[UIControl alloc] init];
self.blackOverBack.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
}
self.blackOverBack.frame = self.bounds;
UIColor *maskColor = [UIColor colorWithWhite:0.0 alpha:0.2];
self.blackOverBack.backgroundColor = maskColor;
[self addSubview:self.blackOverBack];
[self.blackOverBack addTarget:self action:@selector(dissmissView) forControlEvents:UIControlEventTouchUpInside];
CGFloat spaceW = 20;
CGFloat itemW= (kScreenSize.width - spaceW *5)/4;
self.scrollView =[[UIScrollView alloc] init];
CGFloat scrollH= 60 + itemW +spaceW;
CGRect frame = CGRectMake(0,kScreenSize.height -scrollH, self.frame.size.width,scrollH);
[self.scrollView setFrame:frame];
self.scrollView.backgroundColor = COLOR_MIAN;
self.scrollView.alpha = 1;
self.scrollView.showsVerticalScrollIndicator = NO;
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.contentSize = CGSizeMake((spaceW + itemW) *self.titles.count , 160);
[self.blackOverBack addSubview:self.scrollView];
self.imgsArr = [[NSMutableArray alloc] init];
for (NSInteger i =0; i <=3; i++ ) {
UIButton *imgbtn =[UIButton buttonWithType:UIButtonTypeCustom];
imgbtn.frame = CGRectMake(spaceW*(i+1) + itemW*i, 20, itemW, itemW);
[imgbtn addTarget:self action:@selector(sharebtnClick:) forControlEvents:UIControlEventTouchUpInside];
[imgbtn setImage:[UIImage imageNamed:self.imges[i]] forState:UIControlStateNormal];
imgbtn.tag = i;
[self.scrollView addSubview:imgbtn];
[self.imgsArr addObject:imgbtn];
UILabel *title=[[UILabel alloc] initWithFrame:CGRectMake(spaceW*(i+1) + itemW*i, 20 + itemW +20 , itemW, 20)];
title.text = self.titles[i];
title.textAlignment = NSTextAlignmentCenter;
title.textColor = [UIColor whiteColor];
[self.scrollView addSubview:title];
}
}
-(void)shareShow{
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
[UIView animateWithDuration:0.38 animations:^{
[keyWindow addSubview:self];
}];
}
-(void)layoutSubviews{
timer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(showAnima) userInfo:nil repeats:NO];
}
-(void)showAnima{
[self.imgsArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
UIButton*btn=(UIButton *)obj;
CGRect animationFrame = CGRectMake(btn.frame.origin.x, btn.frame.origin.y +10, btn.frame.size.width, btn.frame.size.height);
[UIView animateWithDuration:1.0 delay:1.0 usingSpringWithDamping:0.2 initialSpringVelocity:0 options:
UIViewAnimationOptionAllowUserInteraction animations:^{
btn.frame = animationFrame;
} completion:^(BOOL finished) {
}];
if (stop) {
[self TransitionFlipanimations];
}
}];
}
-(void)TransitionFlipanimations{
[self.imgsArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (idx ==0) {
[UIView transitionWithView:obj duration:0.7 options:UIViewAnimationOptionTransitionFlipFromLeft+UIViewAnimationOptionCurveEaseInOut animations:^{
} completion:^(BOOL finished) {
}];
NSLog(@"......0");
}else if (idx ==1){
[UIView transitionWithView:obj duration:0.8 options:UIViewAnimationOptionTransitionFlipFromLeft +UIViewAnimationOptionCurveEaseInOut animations:^{
} completion:^(BOOL finished) {
}];
NSLog(@"......1");
}else if (idx ==2){
[UIView transitionWithView:obj duration:0.9 options:UIViewAnimationOptionTransitionFlipFromLeft +UIViewAnimationOptionCurveEaseInOut animations:^{
} completion:^(BOOL finished) {
}];
NSLog(@"......2");
}else if (idx ==3){
[UIView transitionWithView:obj duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft +UIViewAnimationOptionCurveEaseInOut animations:^{
} completion:^(BOOL finished) {
}];
NSLog(@"......3");
}
}];
}
-(void)sharebtnClick:(UIButton *)btn{
for (NSInteger i = 0; i<self.subviews.count; i++){
UIView *view = self.subviews[i];
if ([view isKindOfClass:[UIButton class]]){
[UIView animateWithDuration:0.3 delay:0.1*i options:UIViewAnimationOptionTransitionCurlDown animations:^{
} completion:^(BOOL finished) {
}];
}
}
[self performSelector:@selector(removeView:) withObject:btn afterDelay:0.38];
}
-(void)dissmissView{
[UIView animateWithDuration:0.38 animations:^{
[timer invalidate];
[self removeFromSuperview];
}];
}
-(void)removeView:(UIButton *)sender{
[UIView animateWithDuration:0.38 animations:^{
[timer invalidate];
[self removeFromSuperview];
}];
[self.delegate didSelectButWithBtnTag:sender.tag];
}
@end