編輯:關於Android編程
ViewController.m
#import "ViewController.h"
#import "ImageAnimationViewController.h"
@interface ViewController ()
//黑色視圖
@property (nonatomic, strong) UIView *blackView;
//導航欄的按鈕點擊事件
- (IBAction)nextVC:(id)sender;
//初始化界面
- (void)initUserInterface;
#pragma mark - UIView動畫
////手勢方法
//- (void)tapProcess;
////位移
//- (void)positionAnimation;
////縮放
//- (void)scaleAnimation;
////旋轉
//- (void)rotationAnimation;
////變色
//- (void)colorAnimation;
////透明度
//- (void)alphAnimation;
////結束
//- (void)endAnimation;
////UIView動畫回調方法
//- (void)showViewAnimationDidStop:(NSString *)animationID;
#pragma mark - block方法
//位移
- (void)positionAnimationBlock;
//縮放
- (void)scaleAnimationBlock;
//旋轉
- (void)rotationAnimationBlock;
//顏色
- (void)colorAnimationBlock;
//透明度
- (void)alphAnimationBlock;
//返回
- (void)endAnimationBlock;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initUserInterface];
}
#pragma mark - initUserInterface method
- (void)initUserInterface
{
//黑色背景視圖
self.view.backgroundColor = [UIColor whiteColor];
_blackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
_blackView.backgroundColor = [UIColor blackColor];
[self.view addSubview:_blackView];
/**< 為黑色背景視圖添加點擊手勢 */
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapProcess)];
[_blackView addGestureRecognizer:tapGesture];
}
#pragma mark - 手勢方法
- (void)tapProcess{
[self positionAnimationBlock];
}
#pragma block動畫
//位移
- (void)positionAnimationBlock{
[UIView animateWithDuration:0.5 animations:^{
_blackView.center = CGPointMake(CGRectGetMidX(self.view.frame), CGRectGetMidY(self.view.frame)- 100);
} completion:^(BOOL finished) {
[self scaleAnimationBlock];
}];
}
//縮放
- (void)scaleAnimationBlock{
[UIView animateWithDuration:0.5 animations:^{
_blackView.transform = CGAffineTransformMakeScale(1.5, 1.5);
} completion:^(BOOL finished) {
[self rotationAnimationBlock];
}];
}
//旋轉
- (void)rotationAnimationBlock{
[UIView animateWithDuration:0.5 animations:^{
_blackView.transform = CGAffineTransformRotate(_blackView.transform, M_PI);
} completion:^(BOOL finished) {
[self colorAnimationBlock];
}];
}
//變色
- (void)colorAnimationBlock
{
[UIView animateWithDuration:0.5 animations:^{
_blackView.backgroundColor = [UIColor redColor];
} completion:^(BOOL finished) {
[self alphAnimationBlock];
}];
}
//透明度(漸變)
- (void)alphAnimationBlock
{
[UIView animateWithDuration:0.5 animations:^{
_blackView.alpha = 0.5;
} completion:^(BOOL finished) {
[self endAnimationBlock];
}];
}
//結束
- (void)endAnimationBlock{
[UIView animateWithDuration:1 animations:^{
//視圖恢復到初始狀態
_blackView.backgroundColor = [UIColor blackColor];
_blackView.alpha = 1.0;
_blackView.center = CGPointMake(CGRectGetMidX(_blackView.bounds), CGRectGetMidX(_blackView.bounds));
// CGAffineTransformIdentity:移除所有的變幻屬性
_blackView.transform = CGAffineTransformIdentity;
//轉場動畫(效果)
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_blackView cache:NO];
} completion:^(BOOL finished) {
}];
}
#pragma mark - UIView動畫
////位移
//- (void)positionAnimation{
// //開始動畫
// [UIView beginAnimations:@"position" context:nil];
// //持續時間
// [UIView setAnimationDuration:1];
// //線性規律
// [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
// //添加代理
// [UIView setAnimationDelegate:self];
// //設置回調方法
// [UIView setAnimationDidStopSelector:@selector(showViewAnimationDidStop:)];
// //核心動畫
// _blackView.center = CGPointMake(CGRectGetMidX(self.view.frame), CGRectGetMidY(self.view.frame)- 100);
// //提交動畫
// [UIView commitAnimations];
//}
//
////縮放
//- (void)scaleAnimation{
// //開始動畫
// [UIView beginAnimations:@"scale" context:nil];
// //持續時間
// [UIView setAnimationDuration:0.7];
// //線性規律
// [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
// //添加代理
// [UIView setAnimationDelegate:self];
// //設置回調方法
// [UIView setAnimationDidStopSelector:@selector(showViewAnimationDidStop:)];
//
// //核心動畫
// /**< 設置動畫類型:縮放
// transform:變化屬性(可實現旋轉和所縮放動畫)
// CGAffineTransformScale...:在新生成的屬性變換基礎之上繼續執行
// CGAffineTransformMakeScale...:在最初始(最原始)的屬性基礎上做變化 */
//
// _blackView.transform = CGAffineTransformMakeScale(1.5, 1.5);
//
// //在變化後的基礎上還可持續放大
// //_blackView.transform = CGAffineTransformScale(_blackView.transform, 1.5, 1.5);
// //提交動畫
// [UIView commitAnimations];
//}
//
////旋轉
//- (void)rotationAnimation{
// //開始動畫
// [UIView beginAnimations:@"rotation" context:nil];
// //持續時間
// [UIView setAnimationDuration:0.5];
// //線性規律
// [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
// //添加代理
// [UIView setAnimationDelegate:self];
// //設置回調方法
// [UIView setAnimationDidStopSelector:@selector(showViewAnimationDidStop:)];
//
// // 設置動畫類型:旋轉
// // angle:角度
// // M_PI:180°
// // M_PI_2:90°
// // M_PI_4:45°
// //旋轉之後縮回原來的大小
// //_blackView.transform = CGAffineTransformMakeRotation(M_PI);
// //旋轉之後保持放大後的大小
// _blackView.transform = CGAffineTransformRotate(_blackView.transform, M_PI);
// //提交動畫
// [UIView commitAnimations];
//
//}
//
////變色
//- (void)colorAnimation{
// //開始動畫
// [UIView beginAnimations:@"color" context:nil];
// //持續時間
// [UIView setAnimationDuration:0.5];
// //線性規律
// [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
// //添加代理
// [UIView setAnimationDelegate:self];
// //設置回調方法
// [UIView setAnimationDidStopSelector:@selector(showViewAnimationDidStop:)];
// //核心動畫
// _blackView.backgroundColor = [UIColor redColor];
// //提交動畫
// [UIView commitAnimations];
//}
//
////透明度
//- (void)alphAnimation{
// //開始動畫
// [UIView beginAnimations:@"alph" context:nil];
// //持續時間
// [UIView setAnimationDuration:0.5];
// //線性規律
// [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
// //添加代理
// [UIView setAnimationDelegate:self];
// //設置回調方法
// [UIView setAnimationDidStopSelector:@selector(showViewAnimationDidStop:)];
// //核心動畫
// _blackView.alpha = 0.5;
// //提交動畫
// [UIView commitAnimations];
//
//}
//
////結束
//- (void)endAnimation{
// //開始動畫
// [UIView beginAnimations:@"end" context:nil];
// //持續時間
// [UIView setAnimationDuration:1];
// //線性規律
// [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
// //添加代理
// [UIView setAnimationDelegate:self];
// //設置回調方法
// [UIView setAnimationDidStopSelector:@selector(showViewAnimationDidStop:)];
//
// //視圖恢復到初始狀態
// _blackView.backgroundColor = [UIColor blackColor];
// _blackView.alpha = 1.0;
// _blackView.center = CGPointMake(CGRectGetMidX(_blackView.bounds), CGRectGetMidX(_blackView.bounds));
//
// // CGAffineTransformIdentity:移除所有的變幻屬性
// _blackView.transform = CGAffineTransformIdentity;
//
//
// //轉場動畫(效果)
// [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_blackView cache:NO];
//
// //提交動畫
// [UIView commitAnimations];
//}
//
//#pragma mark - UIView動畫回調方法
//- (void)showViewAnimationDidStop:(NSString *)animationID{
// if ([animationID isEqualToString:@"position"]) {
// [self scaleAnimation];
// }else if ([animationID isEqualToString:@"scale"]){
// [self rotationAnimation];
// }else if ([animationID isEqualToString:@"rotation"]){
// [self colorAnimation];
// }else if ([animationID isEqualToString:@"color"]){
// [self alphAnimation];
// }else if ([animationID isEqualToString:@"alph"]){
// [self endAnimation];
// }
//
//}
- (IBAction)nextVC:(id)sender {
ImageAnimationViewController *imageVC = [[ImageAnimationViewController alloc]init];
[self.navigationController pushViewController:imageVC animated:YES];
}
@end
#import "ImageAnimationViewController.h"
#define IMAGE_WITH_NAME(name)[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]]
#define SCREEN_WEIGH [UIScreen mainScreen].bounds.size.width
@interface ImageAnimationViewController ()
@property (nonatomic, strong) UIImageView *imageView;
- (void)initUserInterface;
@end
@implementation ImageAnimationViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initUserInterface];
}
- (void)initUserInterface{
self.view.backgroundColor = [UIColor cyanColor];
//
NSMutableArray *imageArray = [NSMutableArray array];
//創建圖片數組
for (int i = 0; i < 138; i ++) {
NSString *imageName = [NSString stringWithFormat:@"%d",i];
//第一種
// UIImage *image = [UIImage imageNamed:imageName];
//第二種(加載大量的圖片)
// NSString *pathString = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"];
// UIImage *image = [UIImage imageWithContentsOfFile:pathString];
//第三種(宏定義)
UIImage *image = IMAGE_WITH_NAME(imageName);
[imageArray addObject:image];
}
//創建圖片視圖
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 200, SCREEN_WEIGH, 400)];
[self.view addSubview:imageView];
//為其添加圖片數組
imageView.animationImages = imageArray;
//動畫時長
imageView.animationDuration = 2;
self.imageView = imageView;
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(100, 100, 80, 60);
button.backgroundColor = [UIColor whiteColor];
[button setTitle:@"stop" forState:UIControlStateNormal];
[button addTarget:self action:@selector(stopProcess) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (void)stopProcess{
[self.imageView stopAnimating];
}
//獲取點擊屏幕動作
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
// 1. 獲取touch
UITouch *touch = [touches anyObject];
// 2. 獲取當期點
CGPoint point = [touch locationInView:self.view];
NSLog(@"%@", NSStringFromCGPoint(point));
// 3. 動畫開始
[_imageView startAnimating];
}
- (void)viewWillDisappear:(BOOL)animated{
//animationImages數組無法釋放,所以需要手動釋放,但是不能直接寫 self.catImageView.animationImages = nil;因為動畫是異步,還沒執行完,數組就釋放會崩潰的。所以可以使用performSelector讓動畫在剛好做完後延遲釋放,或者在viewWillDisappear
self.imageView.animationImages = nil;
}
@end
Android指紋識別API初試
在android6.0之後谷歌對指紋識別進行了官方支持,今天還在放假,所以就隨意嘗試了一下這個api,但是遇到了各種各樣的問題 ①在使用FingerPrintM
小米手機(MIUI系統)怎麼在撥號界面直接充值話費
如果你是小米手機或小米MIUI系統的用戶,充值話費可以很簡單,你知道嗎?還在打開電腦、登陸淘寶,搜索充值話費的店嗎?看看小米MIUI系統是怎麼在撥號界面輕松
Android NDK學習筆記9-JNI調用Java方法
與域一樣,java中有兩類方法:實例方法和靜態方法。JNI提供訪問兩類方法的函數,例如:public class JavaClass {// 實例方法private St
(Android review)打開Activity返回結果
一、基本知識點其實要完成這個功能很簡單:1、MainActivitystartActivityForResult(intent, 100);//第二個是請求碼@Overr