iOS-仿微信摇一摇

热门标签

,

特别声明:文章多为网络转载,资源使用一般不提供任何帮助,特殊资源除外,如有侵权请联系!

//
//  ViewController.m
//  摇一摇
//
//  Created by ZFJ_APPLE on 16/1/25.
//  Copyright © 2016年张福杰. All rights reserved.
//
 
#import "ViewController.h"
#import "LZAudioTool.h"
#import <AVFoundation/AVFoundation.h>
 
#define kWidth [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height
 
@interface ViewController ()
 
 
@property (nonatomic,strong) UIImageView *upImage;      //背景图片
 
@property (nonatomic,strong) UIImageView *downImage;    //上一半手的图片
 
@property (nonatomic,strong) UIView *upView;            //下一半手
 
@property (nonatomic,strong) UIView *downView;          //下一半手的图片
 
 
@end
 
@implementation ViewController
 
- (void)viewDidLoad
{
    [superviewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self uiConfig];
}
 
- (void)uiConfig
{
    UIImageView *image = [[UIImageViewalloc]initWithFrame:CGRectMake(0,kHeight / 4,kWidth, kHeight /2)];
    image.image = [UIImageimageNamed:@"ShakeHideImg_women@2x.png"];
    [self.viewaddSubview:image];
    
    _upView = [[UIView alloc]initWithFrame:CGRectMake(0,0, kWidth, kHeight / 2)];
    _upView.backgroundColor = [UIColor blackColor];
    
    _upImage = [[UIImageView alloc]initWithFrame:CGRectMake(50, kHeight /4, kWidth - 100, kHeight /4)];
    _upImage.image = [UIImage imageNamed:@"Shake_Logo_Up@2x.png"];
    
    [_upView addSubview:_upImage];
    [self.view addSubview:_upView];
    
    
    
    _downView = [[UIView alloc]initWithFrame:CGRectMake(0, kHeight /2, kWidth, kHeight / 2)];
    _downView.backgroundColor = [UIColor blackColor];
    
    _downImage = [[UIImageView alloc]initWithFrame:CGRectMake(50,0, kWidth - 100, kHeight /4)];
    _downImage.image = [UIImage imageNamed:@"Down@2x.png"];
    
    [_downView addSubview:_downImage];
    [self.view addSubview:_downView];
}
 
#pragma mark - 开始摇晃就会调用
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    //开始摇晃设置动画
    [UIView animateWithDuration:1 animations:^{
        
        _upView.frame = CGRectMake(0, -(kHeight /4), kWidth, kHeight / 2);
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:1 animations:^{
            
            _upView.frame = CGRectMake(0, 0, kWidth, kHeight / 2);
            
        }];
    }];
    
    [UIView animateWithDuration:1 animations:^{
        
        _downView.frame = CGRectMake(0, kHeight /2 + kHeight / 4, kWidth, kHeight /2);
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:1 animations:^{
           
            _downView.frame = CGRectMake(0, kHeight /2, kWidth, kHeight / 2);
 
        }];
        
    }];
    //播放摇晃声音
    [LZAudioTool playMusic:@"1.mp3"];
}
 
#pragma mark - 摇晃结束就会调用
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    //摇晃结束
}
 
#pragma mark - 摇晃被打断就会调用
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    //摇晃被打断
}
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
@end

Demo下载地址:http://pan.baidu.com/s/1bohohIJ

标签:

未经允许不得转载:作者:SheaYang, 转载或复制请以 超链接形式 并注明出处 技术Dog|博客
原文地址:《iOS-仿微信摇一摇》 发布于2019-10-31

分享到:
赞(0) 打赏

评论 抢沙发

9 + 8 =


iOS-仿微信摇一摇

长按图片转发给朋友

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

Vieu4.0主题
专业打造轻量级个人企业风格博客主题!专注于前端开发,全站响应式布局自适应模板。

登录

忘记密码 ?