2012年10月27日 星期六

UIView的Animation(六)

在UIView使用旋轉的Function

CGAffineTransformRotate --對影像作一個以中心為圓心的旋轉,並會修改image的資料
CGAffineTransformMakeRotation-只顯示旋轉結果,不會修改image資料,因此只會顯示旋轉一次的結果。


example
Image1.transform = CGAffineTransformRotate(Image1.transform, 角度*PI/180);
Image1.transform = CGAffineTransformMakeRotation(角度*PI/180);


以下例子改自前一篇

1. 增加一個角度的Slider




2. 將元件註冊到mainViewController.h
@property (weak, nonatomic) IBOutlet UISlider *rotationSlider;
@property (weak, nonatomic) IBOutlet UILabel *rotationLabel;



3. 增加相關的程式碼到mainViewController.m
@synthesize rotationLabel;
@synthesize rotationSlider;


int change = 1;

#define kDuration 2   // 动画持续时间(秒)

#define PI   3.14159

.....

- (IBAction)transferAction:(id)sender {
   
    UIButton *button = (UIButton *)sender;
    NSInteger tag = button.tag;
   
    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:kDuration];
   
    switch (tag) {
        case 105:
            [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
            break;
        case 106:
            [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
            break;
        case 107:
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
            break;
        case 108:
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
            break;
        default:
            break;
    }
   
    self.typeID += 1;
    if (self.typeID > 3) {
        self.typeID = 0;
    }
   
    if (twoImageMode.on == YES) {
       NSUInteger image1 = [[self.view subviews] indexOfObject:self.Image1];
       NSUInteger image2 = [[self.view subviews] indexOfObject:self.Image2];
       [self.view exchangeSubviewAtIndex:image1 withSubviewAtIndex:image2];
    }
    else {
       
        [self removeImageView];
   
        if (image1Enable.on == YES) {
       
           
            if (unlimitChange.on == YES)
                Image1.transform = CGAffineTransformScale(Image1.transform, xValueSlider.value
                                                      , yValueSlider.value);
            else
                Image1.transform = CGAffineTransformMakeScale(xValueSlider.value
                                                          , yValueSlider.value);
           
           
             if (unlimitChange.on == YES)
                Image1.transform = CGAffineTransformRotate(Image1.transform, 

                                           rotationSlider.value*PI/180);
             else
                Image1.transform = CGAffineTransformMakeRotation(rotationSlider.value*PI/180);



           
            Image1.alpha = transparentSlider.value;
           
            [self.view  addSubview:Image1];
            [self.view sendSubviewToBack:Image1];
        }
        else  {
           
            if (unlimitChange.on == YES)
                Image2.transform = CGAffineTransformScale(Image2.transform, xValueSlider.value
                                                          , yValueSlider.value);
            else
                Image2.transform = CGAffineTransformMakeScale(xValueSlider.value
                                                              , yValueSlider.value);
           
            if (unlimitChange.on == YES)
                Image2.transform = CGAffineTransformRotate(Image2.transform, 

                                rotationSlider.value*PI/180);
            else
                Image2.transform = CGAffineTransformMakeRotation(rotationSlider.value*PI/180);

           
            Image2.alpha = transparentSlider.value;
           
            [self.view  addSubview:Image2];
            [self.view sendSubviewToBack:Image2];
        }
    }
       
       
    [UIView setAnimationDelegate:self];
    // 动画完毕后调用某个方法
    //[UIView setAnimationDidStopSelector:@selector(animationFinished:)];
    [UIView commitAnimations];
   
    if (change == 1)
        change = 2;
    else
        change = 1;
}

.....
- (IBAction)rotationAngleChange:(id)sender {
   
    rotationLabel.text = [NSString stringWithFormat:@"旋轉角度:%3.1f度", rotationSlider.value];
   
 }



4. 執行結果,顯示X方向反轉及90度旋轉的不同





2012年10月26日 星期五

UIView的Animation(五)

在UIView使用翻转和缩放的效果,就必須使用下面這兩個Function

CGAffineTransformMakeScale  -- 只顯示對原始圖的一次變動,原始圖的原始資料未改變。
CGAffineTransformScale           -- 對原始圖的原始資料不斷的變動。
example
         
Image1.transform = CGAffineTransformScale(Image1.transform, xValue  , yValue);
               
Image1.transform = CGAffineTransformMakeScale(xValue, yValue);

xValue --> X-AXIS方向

yValue --> Y-AXIS方向
所有的值,負值表示反轉(鏡射),小於一表縮小,大於一表放大,1大小不變,0縮成一點(看不見)。
 CGAffineTransformScale(Image1.transform, -1  , -1);表X/Y方向都反轉
 CGAffineTransformScale(Image1.transform, 0.8  , 0.8 );表X/Y方向都縮小20%,變成八折。
 CGAffineTransformScale(Image1.transform, -0.8  , -0.8 );表X/Y方向都縮小20%,並且反轉方向。


可參考矩陣數學中的計算。

以下的例子改自UIView的Animation(四)

1. 將入新的Button/Label/Switch/Slider

 2. 設定元件到mainViewController.h
#import <UIKit/UIKit.h>

@interface mainViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIButton *functionButtons;

@property (nonatomic) UIImageView *Image1;
@property (nonatomic) UIImageView *Image2;
@property (weak, nonatomic) IBOutlet UISlider *transparentSlider;
@property (weak, nonatomic) IBOutlet UISlider *xValueSlider;
@property (weak, nonatomic) IBOutlet UISlider *yValueSlider;
@property (weak, nonatomic) IBOutlet UISwitch *image1Enable;
@property (weak, nonatomic) IBOutlet UISwitch *twoImageMode;
@property (weak, nonatomic) IBOutlet UILabel *transparentLabel;
@property (weak, nonatomic) IBOutlet UILabel *image1Label;
@property (weak, nonatomic) IBOutlet UILabel *twoImageLabel;
@property (weak, nonatomic) IBOutlet UILabel *xValueLabel;
@property (weak, nonatomic) IBOutlet UILabel *yValueLabel;
@property (weak, nonatomic) IBOutlet UISwitch *unlimitChange;
@property (weak, nonatomic) IBOutlet UILabel *unlimitChangeLabel;

@property (nonatomic, assign) NSInteger typeID;


@end

3. 修改mainViewController.m程式碼
#import "mainViewController.h"

@interface mainViewController ()

@end

@implementation mainViewController

@synthesize Image1, Image2;
@synthesize typeID;

@synthesize transparentLabel;
@synthesize xValueSlider;
@synthesize yValueSlider;
@synthesize twoImageMode;
@synthesize image1Enable;

@synthesize twoImageLabel;
@synthesize image1Label;
@synthesize transparentSlider;
@synthesize xValueLabel;
@synthesize yValueLabel;

@synthesize unlimitChange;
@synthesize unlimitChangeLabel;

int change = 1;

#define kDuration 2   // 动画持续时间(秒)

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
   
    Image1= [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024,768)];
   
    Image2= [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
   
    [Image1 setImage:[UIImage imageNamed:@"mount1.jpg"]];
   
   
    [Image2 setImage:[UIImage imageNamed:@"mount2.jpg"]];
   
    [self.view  addSubview:Image1];
    [self.view  addSubview:Image2];
   
    [self.view sendSubviewToBack:Image1];
    [self.view sendSubviewToBack:Image2];
   
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)transferAction:(id)sender {
   
    UIButton *button = (UIButton *)sender;
    NSInteger tag = button.tag;
   
    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:kDuration];
   
    switch (tag) {
        case 105:
            [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
            break;
        case 106:
            [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
            break;
        case 107:
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
            break;
        case 108:
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
            break;
        default:
            break;
    }
   
    self.typeID += 1;
    if (self.typeID > 3) {
        self.typeID = 0;
    }
   
    if (twoImageMode.on == YES) {
       NSUInteger image1 = [[self.view subviews] indexOfObject:self.Image1];
       NSUInteger image2 = [[self.view subviews] indexOfObject:self.Image2];
       [self.view exchangeSubviewAtIndex:image1 withSubviewAtIndex:image2];
    }
    else {
       
        [self removeImageView];
   
        if (image1Enable.on == YES) {
       
           
            if (unlimitChange.on == YES)
                Image1.transform = CGAffineTransformScale(Image1.transform, xValueSlider.value
                                                      , yValueSlider.value);
            else
                Image1.transform = CGAffineTransformMakeScale(xValueSlider.value
                                                          , yValueSlider.value);
               
            Image1.alpha = transparentSlider.value;
           
            [self.view  addSubview:Image1];
            [self.view sendSubviewToBack:Image1];
        }
        else  {
           
            if (unlimitChange.on == YES)
                Image2.transform = CGAffineTransformScale(Image2.transform, xValueSlider.value
                                                          , yValueSlider.value);
            else
                Image2.transform = CGAffineTransformMakeScale(xValueSlider.value
                                                              , yValueSlider.value);
           
           
            //Image2.transform = CGAffineTransformScale(Image2.transform, xValueSlider.value
            //                                          , yValueSlider.value);
           
            Image2.alpha = transparentSlider.value;
           
            [self.view  addSubview:Image2];
            [self.view sendSubviewToBack:Image2];
        }
    }
       
       
    [UIView setAnimationDelegate:self];
    // 动画完毕后调用某个方法
    //[UIView setAnimationDidStopSelector:@selector(animationFinished:)];
    [UIView commitAnimations];
   
    if (change == 1)
        change = 2;
    else
        change = 1;
}

-(void) removeImageView
{
    for(UIView *subview in [self.view subviews]) {
        if([subview isKindOfClass:[UIImageView class]]) {
            [subview removeFromSuperview];
        } else {
            // Do nothing - not a UIButton or subclass instance
        }
    }

}
- (IBAction)transparentChange:(id)sender {
   
    transparentLabel.text = [NSString stringWithFormat:@"透明度:%2.2f",transparentSlider.value];
   
    if (twoImageMode.on == YES) {
        [self removeImageView];
       
        Image1.alpha = transparentSlider.value;
        Image2.alpha = transparentSlider.value;
       
        [self.view  addSubview:Image1];
        [self.view  addSubview:Image2];
       
        [self.view sendSubviewToBack:Image1];
        [self.view sendSubviewToBack:Image2];

    }
}
- (IBAction)xValueChange:(id)sender {

    if (xValueSlider.value >1)
         xValueLabel.text = [NSString stringWithFormat:@"X方向放大:%2.2f",xValueSlider.value];
    else if (xValueSlider.value <1 &&
             xValueSlider.value >0)
         xValueLabel.text = [NSString stringWithFormat:@"X方向縮小:%2.2f",xValueSlider.value];
    else if (xValueSlider.value >-1 &&
             xValueSlider.value <0)
        xValueLabel.text = [NSString stringWithFormat:@"X方向反轉縮小:%2.2f",xValueSlider.value];
    else if (xValueSlider.value <-1)
        xValueLabel.text = [NSString stringWithFormat:@"X方向反轉放大:%2.2f",xValueSlider.value];
    else if (xValueSlider.value ==0)
        xValueLabel.text = [NSString stringWithFormat:@"X方向水平消失:%2.2f",xValueSlider.value];
    else
        xValueLabel.text = [NSString stringWithFormat:@"X方向不變:%2.2f",xValueSlider.value];
   

}
- (IBAction)yValueChange:(id)sender {

    if (yValueSlider.value >1)
        yValueLabel.text = [NSString stringWithFormat:@"Y方向放大:%2.2f",yValueSlider.value];
    else if (yValueSlider.value <1 &&
             yValueSlider.value >0)
        yValueLabel.text = [NSString stringWithFormat:@"Y方向縮小:%2.2f",yValueSlider.value];
    else if (yValueSlider.value >-1 &&
             yValueSlider.value <0)
        yValueLabel.text = [NSString stringWithFormat:@"Y方向反轉縮小:%2.2f",yValueSlider.value];
    else if (yValueSlider.value <-1)
        yValueLabel.text = [NSString stringWithFormat:@"Y方向反轉放大:%2.2f",yValueSlider.value];
    else if (yValueSlider.value ==0)
        yValueLabel.text = [NSString stringWithFormat:@"Y方向水平消失:%2.2f",yValueSlider.value];
    else
        yValueLabel.text = [NSString stringWithFormat:@"Y方向不變:%2.2f",yValueSlider.value];

}
- (IBAction)selImage:(id)sender {
   
    if (image1Enable.on == YES)
        image1Label.text = @"選擇圖一";
    else
        image1Label.text = @"選擇圖二";

}
- (IBAction)imageModeChange:(id)sender {

    if (twoImageMode.on == YES) {
        twoImageLabel.text = @"兩圖切換模式";
       
        [self removeImageView];
       
        [self.view  addSubview:Image1];
        [self.view  addSubview:Image2];
       
        [self.view sendSubviewToBack:Image1];
        [self.view sendSubviewToBack:Image2];
    }
    else
        twoImageLabel.text = @"單圖切換模式";

}
- (IBAction)timesChange:(id)sender {
   
    if (unlimitChange.on == YES)
        unlimitChangeLabel.text = @"無限制變動";
    else
        unlimitChangeLabel.text = @"原圖變動一次";
   
}


@end

4. 執行結果,可以看到切換後,大小及方向都可改變


2012年10月25日 星期四

Core Animation的基本使用(ㄧ)



Core Animation是利用Quartz Core framework來實作的一個動畫方式,一般是用在切換頁面及影像時,所展現的一種特殊效果。此處有一點UIView Animation的味道,只是做法不同。但使用Core Animation的效果更多樣化,只是用法也稍稍複雜了點。

Core Animation的最大好处是可以帮助Mac或者iPhone的开发者减少代码量。因为如果你想用Core Image或者Open GL实现界面的动画特效,其实也是可以的,主要是非常麻烦。而用Core Animation可以极大简化开发难度和减少代码量。 


CA API为iPhone应用程序提供了高度灵活的动画解决方案。但是须知:CATransition只针对图层,不针对视图。图层是Core Animation与每个UIView产生联系的工作层面。使用Core Animation时,应该将CATransition应用到视图的默认图层([myView layer]而不是视图本身。

 
使用CATransition类实现动画,只需要建立一个Core Animation对象,设置它的参数,然后把这个带参数的过渡添加到图层即可。
使用要引入QuartzCore.framework 代码#import <QuartzCore/QuartzCore.h>
CATransition动画使用了类型type和子类型subtype两个概念。type属性指定了过渡的种类( 淡化、推挤、揭开、覆盖)。subtype设置了过渡的方向(从上、下、左、右)。另外,CATransition私有的动画类型有(立方体、吸收、翻转、波纹、翻页、反翻页、镜头开、镜头关)。此八種很少用,主要有两点:1、后者还没有经过官方的发布,很多资料都没有去介绍;2、考虑到其随时都会被官方更改,为着程序的稳定性等因素不去采用。


詳細資料可參考Apple 文件

以下是 Class 階層圖

主要的Class 有CALayer / CAAnimation / CAtransition


以下先試驗CATransition的动画效果

     (
       kCATransitionFade淡出|
       kCATransitionMoveIn覆盖原图|
       kCATransitionPush推出|
       kCATransitionReveal底部显出来
     )
    
    [animation setType:kCATransitionReveal/...];

效果共有十二種
fade     //交叉淡化过渡(不支持过渡方向)  == kCATransitionFade淡出  也可以為 @" ",但中間要有空格。            

push     //新视图把旧视图推出去   == kCATransitionPush推出
moveIn   //新视图移到旧视图上面   == kCATransitionMoveIn覆盖原图
reveal   //将旧视图移开,显示下面的新视图  == kCATransitionReveal
cube     //立方体翻滚效果
oglFlip  //上下左右翻转效果
suckEffect   //收缩效果,如一块布被抽走(不支持过渡方向)
rippleEffect //滴水效果(不支持过渡方向)
pageCurl     //向上翻页效果
pageUnCurl   //向下翻页效果
cameraIrisHollowOpen  //相机镜头打开效果(不支持过渡方向)
cameraIrisHollowClose //相机镜头关上效果(不支持过渡方向) 


使用方法
animation.type = kCATransitionFade;
or
animation.type = @"fade";
兩種效果都是一樣的


动画方向:  但 kCATransitionFade 不支持Subtype 
     (
       kCATransitionFromRight|
       kCATransitionFromLeft|
       kCATransitionFromTop|
       kCATransitionFromBottom
     )
[animation setSubtype:kCATransitionFromBottom/...];

使用方法
animation.subtype = kCATransitionFromLeft;

其中只有這幾種有支援方向變化。
push     //新视图把旧视图推出去   == kCATransitionPush推出
moveIn   //新视图移到旧视图上面   == kCATransitionMoveIn覆盖原图
reveal   //将旧视图移开,显示下面的新视图  == kCATransitionReveal
cube     //立方体翻滚效果
oglFlip  //上下左右翻转效果 

pageCurl     //向上翻页效果
pageUnCurl   //向下翻页效果 



整個基本用法
//宣告一個CATransition
CATransition *transition = [CATransition animation];
//細部設定
[transition setDelegate:self];
[transition setDuration:1.0f];
//動畫內容
[transition setType:kCATransitionFade];
[transition setSubtype:kCATransitionFromRight];
//執行動畫
[[imageView layer] addAnimation:transition forKey:@"myTransition"];


以下是一個實驗例

1. 開一個專案

2. 加入兩個風景圖檔


3. 在StoryBoard加上13個Button,並加上Tag辨識





4. 加上QuartzCore FrameWork



5. 在mainViewController.h加上所需變數
 #import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

@interface mainViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIButton *fixedDirectionButton;

@property (weak, nonatomic) IBOutlet UIButton *functionButton;

@property (nonatomic) UIImageView *Image1;
@property (nonatomic) UIImageView *Image2;

@property (nonatomic, assign) NSInteger typeID;

@end

6. 在mainViewController.m加上程式碼
#import "mainViewController.h"

@interface mainViewController ()

@end

@implementation mainViewController

@synthesize functionButton;
@synthesize fixedDirectionButton;

@synthesize Image1, Image2;
@synthesize typeID;

#define kDuration 2   // 动画持续时间(秒)


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
   
    Image1= [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024,768)];
   
    Image2= [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
   
    [Image1 setImage:[UIImage imageNamed:@"mount1.jpg"]];
   
   
    [Image2 setImage:[UIImage imageNamed:@"mount2.jpg"]];
   
    [self.view  addSubview:Image1];
    [self.view  addSubview:Image2];
   
    [self.view sendSubviewToBack:Image1];
    [self.view sendSubviewToBack:Image2];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)functionActive:(id)sender {
   
    UIButton *button = (UIButton *)sender;
    NSInteger tag = button.tag;
   
    CATransition *animation = [CATransition animation];
    animation.delegate = self;
    animation.duration = kDuration;
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
   
    switch (tag) {
        case 101:
            animation.type = kCATransitionFade;
            break;
        case 102:
            animation.type = kCATransitionPush;
            break;
        case 103:
            animation.type = kCATransitionReveal;
            break;
        case 104:
            animation.type = kCATransitionMoveIn;
            break;
        case 201:
            animation.type = @"cube";
            break;
        case 202:
            animation.type = @"suckEffect";
            break;
        case 203:
            animation.type = @"oglFlip";
            break;
        case 204:
            animation.type = @"rippleEffect";
            break;
        case 205:
            animation.type = @"pageCurl";
            break;
        case 206:
            animation.type = @"pageUnCurl";
            break;
        case 207:
            animation.type = @"cameraIrisHollowOpen";
            break;
        case 208:
            animation.type = @"cameraIrisHollowClose";
            break;
       
        default:
            break;
    }
   
   
    //animation.subtype = kCATransitionFromLeft;
   
    if (fixedDirectionButton.titleLabel.backgroundColor != [UIColor redColor]) {
        switch (self.typeID) {
            case 0:
                animation.subtype = kCATransitionFromLeft;
                break;
            case 1:
                animation.subtype = kCATransitionFromBottom;
                break;
            case 2:
                animation.subtype = kCATransitionFromRight;
                break;
            case 3:
                animation.subtype = kCATransitionFromTop;
                break;
            default:
                break;
        }
    }
   
    self.typeID += 1;
    if (self.typeID > 3) {
        self.typeID = 0;
    }
   
    NSUInteger image1 = [[self.view subviews] indexOfObject:self.Image1];
    NSUInteger image2 = [[self.view subviews] indexOfObject:self.Image2];
    [self.view exchangeSubviewAtIndex:image1 withSubviewAtIndex:image2];
   
    [[self.view layer] addAnimation:animation forKey:@"animation"];

}
- (IBAction)fixedDirection:(id)sender {
   
    if (fixedDirectionButton.titleLabel.backgroundColor == [UIColor blueColor])
        fixedDirectionButton.titleLabel.backgroundColor = [UIColor redColor];
    else
        fixedDirectionButton.titleLabel.backgroundColor = [UIColor blueColor];

}

@end


唯一要注意的是,functionActive這個IBAction要將所有的動作Button都拉過來。

7. 執行結果,當固定方向的Button變成紅色之後,所有跟方向有關的動作,都只會固定一種方向。另外,這些方向也跟iPad的垂直方向有關,如果將iPad改成橫放,則方向會跟著改變(上下變左右)。



Apple TV 使用

剛買了Apple TV,用HDMI連上TV,接上電源。第一步當然是將語言設定成中文,然後將WiFi的密碼打入。這樣基本上就可以使用AppleTV上網了,可以選擇看電影的預告片,畫質很好,聲音也很清楚。

開始使用Airplay,將iPad打開,先回到Home區,再連按兩下Home,於是畫面下面就會出現APP執行Bar,手指向右滑,來到最左邊,可以看到中間會有像電視的Icon圖,按Icon然後選擇AppleTV,再將畫面上的Switch滑開。請參考借來的圖
如何在iPad上使用AirPlay

可參考網頁說明
http://chiclin.pixnet.net/blog/post/35985689-%E8%A7%A3%E9%96%8Bapple-tv%E9%8F%A1%E5%83%8F%E8%BC%B8%E5%87%BA%E7%9A%84%E7%A5%95%E5%AF%86


http://ipad.about.com/od/iPad_Guide/ss/How-To-Use-Airplay-On-The-iPad.htm

google翻譯網頁
http://translate.google.com.tw/translate?sl=en&tl=zh-TW&js=n&prev=_t&hl=zh-TW&ie=UTF-8&layout=2&eotf=1&u=http%3A%2F%2Fipad.about.com%2Fod%2FiPad_Troubleshooting%2Fa%2FHow-To-Fix-Airplay-Icon-Missing.htm

但是如果很不幸一直都沒有看到這個電視Icon,就表示網路有問題或是Wifi的頻寬不足,沒辦法用Wifi,就將網路線直接拉到AppleTV,再重複iPad的動作,就應該會看到了。

如果都做了,還是看不到,就將iPad重新開機(長按上面的螢幕關閉鍵來關機,再開機),再重複上面iPad的動作就可以了。

另外如果不想對iPAD重開機,就將語言設定先改回到英語界面,也會出現Icon,只是時間也是很久。

網路上還有另一種說法,將AppleTV電源,重新拔插,就可以解決,但我自己沒試過。

再如果非常非常的不幸,所有上述之法皆已經試過了,都還是不行,請參考下面網頁的參考資料,看看還有什麼方式可以解決了,祝好運。
http://ipad.about.com/od/iPad_Troubleshooting/a/How-To-Fix-Airplay-Icon-Missing.htm

以下是google轉成的翻譯
http://translate.google.com.tw/translate?sl=en&tl=zh-TW&js=n&prev=_t&hl=zh-TW&ie=UTF-8&layout=2&eotf=1&u=http%3A%2F%2Fipad.about.com%2Fod%2FiPad_Troubleshooting%2Fa%2FHow-To-Fix-Airplay-Icon-Missing.htm



2012年10月24日 星期三

UIView的Animation(四)

與前一篇不同的是在實作翻頁相關的動畫形態。

向上翻頁的效果:
//Curl Up
UIViewAnimationTransition transition = UIViewAnimationTransitionCurlUp;


向下翻頁的效果:
//Curl Down
UIViewAnimationTransition transition = UIViewAnimationTransitionCurlDown;


由左向右旋轉的效果:
//Flip From Left
UIViewAnimationTransition transition = UIViewAnimationTransitionFlipFromLeft;


由右向左旋轉的效果:
//Flip From Right
UIViewAnimationTransition transition = UIViewAnimationTransitionFlipFromRight;


無動畫效果,直接變化
UIViewAnimationTransition transition = UIViewAnimationTransitionNone;

以下是實作例
1. 開啓一個專案

2. 加入兩個風景圖檔

3. 對storyBoard加上四個Button,並分別對tag設定105~108


4. 在mainViewController.h註冊Button及UIViewImage變數,Button因為四個合在一起用,因此只註冊一個就可以了。
#import <UIKit/UIKit.h>

@interface mainViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIButton *functionButtons;

@property (nonatomic) UIImageView *Image1;
@property (nonatomic) UIImageView *Image2;

@property (nonatomic, assign) NSInteger typeID;

@end

5. 在mainViewController.m加上程式碼,唯一要注意的是,四個Button都與同一個IBAction聯結。

#import "mainViewController.h"

@interface mainViewController ()

@end

@implementation mainViewController

@synthesize Image1, Image2;
@synthesize typeID;

int change = 1;


#define kDuration 2   // 动画持续时间(秒)

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
   
    Image1= [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024,768)];
   
    Image2= [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
   
    [Image1 setImage:[UIImage imageNamed:@"mount1.jpg"]];
   
   
    [Image2 setImage:[UIImage imageNamed:@"mount2.jpg"]];
   
    [self.view  addSubview:Image1];
    [self.view  addSubview:Image2];
   
    [self.view sendSubviewToBack:Image1];
    [self.view sendSubviewToBack:Image2];

   
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)transferAction:(id)sender {
   
    UIButton *button = (UIButton *)sender;
    NSInteger tag = button.tag;
   
    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:kDuration];
   
    switch (tag) {
        case 105:
            [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
            break;
        case 106:
            [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
            break;
        case 107:
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
            break;
        case 108:
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
            break;
        default:
            break;
    }
   
    self.typeID += 1;
    if (self.typeID > 3) {
        self.typeID = 0;
    }
   
    NSUInteger image1 = [[self.view subviews] indexOfObject:self.Image1];
    NSUInteger image2 = [[self.view subviews] indexOfObject:self.Image2];
    [self.view exchangeSubviewAtIndex:image1 withSubviewAtIndex:image2];
   
    [UIView setAnimationDelegate:self];
    // 动画完毕后调用某个方法
    //[UIView setAnimationDidStopSelector:@selector(animationFinished:)];
    [UIView commitAnimations];
   
    if (change == 1)
        change = 2;
    else
        change = 1;
}


@end

6. 結果因為是動畫不截圖了,特殊點在iPhone/iPad要設成直立。如果改成橫放,則展示的功能會相反(上下變左右),不知是Bug還是原始設計就是如此,此處要在查詢。

2012年10月23日 星期二

UIView的Animation(三)


Apple 提供了四種速度變化。


1. 開始時慢慢加速,結束前慢慢減速:

UIViewAnimationCurve curve = UIViewAnimationCurveEaseInOut;


2. 開始時慢慢加速:

UIViewAnimationCurve curve = UIViewAnimationCurveEaseIn;


3. 結束前慢慢減速:

UIViewAnimationCurve curve = UIViewAnimationCurveEaseOut;


4. 開始到尾也是均速:

UIViewAnimationCurve curve = UIViewAnimationCurveLinear;



以下是一個實作例
1. 開啓一個專案

2. 在storyBoard加上一個Button

3. 在mainViewController.h加上Button的註冊及一個Int變數
#import <UIKit/UIKit.h>

@interface mainViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIButton *changeButton;

@property (nonatomic) int sel;


@end

4. 在mainViewController.m加上程式碼
#import "mainViewController.h"

@interface mainViewController ()

@end

@implementation mainViewController

@synthesize sel;
@synthesize changeButton;


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
   
    sel = 0;
   
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)changeModel:(id)sender {
   
    sel++;
   
    if (sel>4)
        sel = 1;
   
    if (sel == 1)
        [changeButton setTitle:@"UIViewAnimationCurveEaseInOut" forState:UIControlStateNormal];
    else if (sel == 2)
        [changeButton setTitle:@"UIViewAnimationCurveLinear" forState:UIControlStateNormal];
    else if (sel == 3)
        [changeButton setTitle:@"UIViewAnimationCurveEaseIn" forState:UIControlStateNormal];
    else
        [changeButton setTitle:@"UIViewAnimationCurveEaseOut" forState:UIControlStateNormal];
   
    [self moveLabel:sel];
   
}

- (void) moveLabel:(int)sel
{
    UILabel *_actionLabel = [UILabel new]; //產生一個動態的Label
   
    _actionLabel.frame = CGRectMake(0, 0, 100, 100);  //大小
   
    _actionLabel.center = self.view.center;  //位置在view的正中間
   
    UIColor *color;
   
    if (sel == 1)
        color = [UIColor blueColor];
    else if (sel == 2)
        color = [UIColor redColor];
    else if (sel == 3)
        color = [UIColor greenColor];
    else
        color = [UIColor grayColor];
   
    _actionLabel.backgroundColor = color; //底色為藍色
   
    _actionLabel.textAlignment = UITextAlignmentCenter; // 文字放置方法為對齊
   
    _actionLabel.text = @"Hello Action";//動態Label文字展示為Hello Action
   
    [self.view addSubview:_actionLabel];  //將動態的Label放到View上展示
   
    //UIViewAnimationTransition transition = UIViewAnimationTransitionCurlUp;
    //UIViewAnimationTransition transition = UIViewAnimationTransitionFlipFromLeft;
   
    UIViewAnimationCurve curve ;
   
    if (sel == 1)
        curve = UIViewAnimationCurveEaseInOut;
    else if (sel == 2)
        curve = UIViewAnimationCurveLinear;
    else if (sel == 3)
        curve = UIViewAnimationCurveEaseIn;
    else
        curve = UIViewAnimationCurveEaseOut;
   
    [UIView beginAnimations:@"anim" context:NULL];
    [UIView setAnimationCurve:curve];
    //[UIView setAnimationTransition:transition forView:[self view] cache:YES];
    [UIView setAnimationDuration:5];
   
    //[self.view setAlpha:0.3];
   
    _actionLabel.center = CGPointMake(200, 200);
   
    [UIView commitAnimations];
   
}


@end

5.執行結果,讓一個Label往另一個Label移動,使用Button(依序)來控制移動模式。

2012年10月22日 星期一

Image Animation(ㄧ)

影像的連續動畫實作
Xcode版本4.5.1


1. 開啓一個專案



 2. 加入動畫連續的圖檔,本例共六張PNG圖








3. 在mainViewController.m加入程式碼

#import "mainViewController.h"

@interface mainViewController ()

@end

@implementation mainViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
      
    NSArray *hopAnimation;
    hopAnimation=[[NSArray alloc] initWithObjects: //Set array below
                  [UIImage imageNamed:@"1001.png"],
                  [UIImage imageNamed:@"1002.png"],
                  [UIImage imageNamed:@"1003.png"],
                  [UIImage imageNamed:@"1004.png"],
                  [UIImage imageNamed:@"1005.png"],
                  [UIImage imageNamed:@"1006.png"],
                  nil
                  ];
   
    UIImageView *a2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100,200)];
   
    a2.animationImages=hopAnimation;
    a2.animationDuration=3;
   
    //a2.startAnimating = YES;
    [a2  startAnimating];
       
    [self.view addSubview:a2];

   
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


 4.結果截圖錄影



2012年10月21日 星期日

UITextView基本使用(ㄧ)

基本的檔案管理與讀寫(一)增加UITextView的背景圖設定而來,增加了透明的背景圖

1. 增加一個背景圖


2. 在mainViewController.m加入UITextView的背景設定,並加上一個消除輸入鍵盤的機制在觸及按鍵時。
#import "mainViewController.h"

@interface mainViewController ()

@end

@implementation mainViewController

@synthesize textEdit;
@synthesize fileName;
@synthesize filePath;

@synthesize data;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
  
    fileName = @"測試檔";
    filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"txt"];
  
    textEdit.backgroundColor = [UIColor clearColor];
  
    UIImageView *a1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 500, 300)];
    [a1 setImage:[UIImage imageNamed:@"TaiwanMap.jpg"]];
    a1.alpha = 0.1f;
  
    [self.view addSubview:a1];
    [self.view sendSubviewToBack:a1];

  
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)readFile:(id)sender {
  
    if (filePath) {
      
        NSString *contentOfFile = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
      
        textEdit.text = contentOfFile;
    }
  
    [textEdit resignFirstResponder];
  
}
- (IBAction)clearWindow:(id)sender {
  
    textEdit.text = @"";
  
    [textEdit resignFirstResponder];
  
  
}
- (IBAction)saveFile:(id)sender {
    data = textEdit.text;
  
    if (filePath) {
      
        [data writeToFile:filePath atomically:NO encoding:NSUTF8StringEncoding error:nil];
      
    }
  
    [textEdit resignFirstResponder];
  
  
}

@end




4. 結果