今天小編給大家分享一下UIView翻轉(zhuǎn)效果如何實(shí)現(xiàn)的相關(guān)知識(shí)點(diǎn),內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識(shí),所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
成都創(chuàng)新互聯(lián)公司長(zhǎng)期為數(shù)千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為沁源企業(yè)提供專業(yè)的網(wǎng)站制作、成都網(wǎng)站制作,沁源網(wǎng)站改版等技術(shù)服務(wù)。擁有十載豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
新建一個(gè)view-based模板工程,在ViewController文件中添加下面的代碼,即可實(shí)現(xiàn)翻轉(zhuǎn)效果; - (void)viewDidLoad { [super viewDidLoad]; //需要翻轉(zhuǎn)的視圖 UIView *parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 150, 320, 200)]; parentView.backgroundColor = [UIColor yellowColor]; parentView.tag = 1000; [self.view addSubview:parentView]; } //需要在h頭文件聲明下面的動(dòng)作響應(yīng)函數(shù) //在xib文件中添加一個(gè)button,其響應(yīng)函數(shù)為下面的函數(shù) //運(yùn)行程序后,點(diǎn)擊button就看到翻轉(zhuǎn)效果 -(IBAction)ActionFanzhuan{ //獲取當(dāng)前畫圖的設(shè)備上下文 CGContextRef context = UIGraphicsGetCurrentContext(); //開始準(zhǔn)備動(dòng)畫 [UIView beginAnimations:nil context:context]; //設(shè)置動(dòng)畫曲線,翻譯不準(zhǔn),見蘋果官方文檔 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //設(shè)置動(dòng)畫持續(xù)時(shí)間 [UIView setAnimationDuration:1.0]; //因?yàn)闆]給viewController類添加成員變量,所以用下面方法得到viewDidLoad添加的子視圖 UIView *parentView = [self.view viewWithTag:1000]; //設(shè)置動(dòng)畫效果 [UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView:parentView cache:YES]; //從上向下 // [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:parentView cache:YES]; //從下向上 // [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:parentView cache:YES]; //從左向右 // [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:parentView cache:YES];//從右向左 //設(shè)置動(dòng)畫委托 [UIView setAnimationDelegate:self]; //當(dāng)動(dòng)畫執(zhí)行結(jié)束,執(zhí)行animationFinished方法 [UIView setAnimationDidStopSelector:@selector(animationFinished:)]; //提交動(dòng)畫 [UIView commitAnimations]; } //動(dòng)畫效果執(zhí)行完畢 - (void) animationFinished: (id) sender{ NSLog(@"animationFinished !"); } 運(yùn)行程序,點(diǎn)擊按鈕,就能看到動(dòng)畫效果了 下面我自己在parentView上添加了兩個(gè)子視圖實(shí)現(xiàn)動(dòng)畫 - (void)viewDidLoad { [super viewDidLoad]; UIView *parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 150, 320, 200)]; parentView.backgroundColor = [UIColor yellowColor]; parentView.tag = 1000; UIImageView *image1 = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)]; image1.backgroundColor = [UIColor redColor]; image1.tag = 1001; UIImageView *image2 = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)]; image2.backgroundColor = [UIColor blueColor]; image2.tag = 1002; [parentView addSubview:image1]; [parentView addSubview:image2]; [self.view addSubview:parentView]; } -(IBAction)ActionFanzhuan{ CGContextRef context = UIGraphicsGetCurrentContext(); [UIView beginAnimations:nil context:context]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:1.0]; UIView *parentView = [self.view viewWithTag:1000]; [UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView:parentView cache:YES]; // [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:parentView cache:YES]; // [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:parentView cache:YES]; // [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:parentView cache:YES]; NSInteger purple = [[parentView subviews] indexOfObject:[parentView viewWithTag:1002]]; NSInteger maroon = [[parentView subviews] indexOfObject:[parentView viewWithTag:1001]]; [parentView exchangeSubviewAtIndex:purple withSubviewAtIndex:maroon]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(animationFinished:)]; [UIView commitAnimations]; } - (void) animationFinished: (id) sender{ NSLog(@"animationFinished !"); } 另外:之前在viewDidLoad里面寫實(shí)現(xiàn)動(dòng)畫的代碼,但一致未實(shí)現(xiàn)動(dòng)畫效果,原來在viewDidLoad里面執(zhí)行 CGContextRef context = UIGraphicsGetCurrentContext(); 后context的指針為0
以上就是“UIView翻轉(zhuǎn)效果如何實(shí)現(xiàn)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會(huì)為大家更新不同的知識(shí),如果還想學(xué)習(xí)更多的知識(shí),請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
分享標(biāo)題:UIView翻轉(zhuǎn)效果如何實(shí)現(xiàn)
文章來源:http://chinadenli.net/article12/jgiggc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、軟件開發(fā)、關(guān)鍵詞優(yōu)化、品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站排名、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)