2012年4月18日 星期三

Filter4Cam 實作: 15. 調整濾鏡表單位置之一

since: 2012/04/18
update: 2012/04/18


A. 說明:
     目前當 iOS 設備垂直擺放時, 濾鏡表單位於螢幕的最下方, 預留的拍攝按鈕位置會在
     螢幕的最上方,  雖然這樣方便選取濾鏡, 但是在按下拍攝按鈕的過程中, 手容易遮到
     螢幕的部分視線, 因此決定將濾鏡表單位置移至螢幕最上方. 

-------------------------------------------------------------------------------

B. 開啓 ViewController.m 檔案, 修改如下:
....
- (UITableView *)filterListTableView
{  
    if (_filterListTableView == nil) {
        //_filterListTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 380, self.view.frame.size.width, 100) style:UITableViewStyleGrouped];
       
        //@update: kOverlayTableViewRowHeight = 106
        /*
        _filterListTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 374, self.view.frame.size.width, kOverlayTableViewRowHeight) style:UITableViewStyleGrouped];
        */
        //@update: Tune UI
        _filterListTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, kOverlayTableViewRowHeight) style:UITableViewStyleGrouped];
    }
   
    return _filterListTableView;
}
....
- (void)cameraOverlay
{  
    //@update: comment it
    //[self.filterLensImageView setFrame:CGRectMake(20, 80, 280, 280)];
    [self.view addSubview:self.filterLensImageView];
....
}

....
- (void)filterOrientationTransform:(CIImage *)sourceImage
{
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
   
    // 設備垂直擺放
    if (orientation == UIDeviceOrientationPortrait)
    {
        //@add
        self.isPreviousOrientationLandscape = NO;
       
        /*
        [self.coreImageContext drawImage:sourceImage inRect:CGRectMake(23.5, 123.5, 274, 274)
                                fromRect:CGRectMake(23, -517.5, 274, 274)];
         */
        //@update: Tune UI
        [self.coreImageContext drawImage:sourceImage inRect:CGRectMake(23.5, 83.5, 274, 274)
                                // x 越小, 濾鏡越向右; y 負越多, 濾鏡越向上
                                fromRect:CGRectMake(23, -557.5, 274, 274)];
    }
    // 設備垂直 180 度擺放
    else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
       
        //@add
        self.isPreviousOrientationLandscape = NO;
       
        /*
        [self.coreImageContext drawImage:sourceImage inRect:CGRectMake(23.5, 123.5, 274, 274)
                                fromRect:CGRectMake(-458.5, 123, 274, 274)];
         */
        //@update: Tune UI
        [self.coreImageContext drawImage:sourceImage inRect:CGRectMake(23.5, 83.5, 274, 274)
                                // x 負越多, 濾鏡越向左; y 越多, 濾鏡越向上
                                fromRect:CGRectMake(-458.5, 83, 274, 274)];
    }
    // 設備水平向右擺放
    else if (orientation == UIDeviceOrientationLandscapeRight) {

        //@add
        self.isPreviousOrientationLandscape = YES;
       
        /*
        [self.coreImageContext drawImage:sourceImage inRect:CGRectMake(83.5, 23.5, 274, 274)
                                fromRect:CGRectMake(-557, -457.5, 274, 274)];
         */
        //@update: Tune UI
        [self.coreImageContext drawImage:sourceImage inRect:CGRectMake(123.5, 23.5, 274, 274)
                                // x 負越多, 濾鏡越向右; y 負越多, 濾鏡越向上
                                fromRect:CGRectMake(-517, -457.5, 274, 274)];
    }
    // 設備水平向左擺放(最穩定)
    else if (orientation == UIDeviceOrientationLandscapeLeft) {

        //@add
        self.isPreviousOrientationLandscape = YES;
       
        /*
        [self.coreImageContext drawImage:sourceImage inRect:CGRectMake(83.5, 23.5, 274, 274)
                                fromRect:CGRectMake(83.5, 23.5, 274, 274)];
        */
        //@update: Tune UI
        [self.coreImageContext drawImage:sourceImage inRect:CGRectMake(123.5, 23.5, 274, 274)
                                // x 越大, 濾鏡越向左; y 越多, 濾鏡越向上
                                fromRect:CGRectMake(123.5, 23.5, 274, 274)];
    }
    // 其它 (UIDeviceOrientationFaceUp, UIDeviceOrientationFaceDown, UIDeviceOrientationUnknown)
    else {   
       
        //@在此不記錄上一次設備的方向
       
        //@add:上一次設備為水平擺放
        if (self.isPreviousOrientationLandscape == YES) {

            /*
            [self.coreImageContext drawImage:sourceImage inRect:CGRectMake(83.5, 23.5, 274, 274)
                                    fromRect:CGRectMake(83.5, 23.5, 274, 274)];
             */
            //@update: Tune UI
            [self.coreImageContext drawImage:sourceImage inRect:CGRectMake(123.5, 23.5, 274, 274)
                                    // x 越大, 濾鏡越向左; y 越多, 濾鏡越向上
                                    fromRect:CGRectMake(123.5, 23.5, 274, 274)];
        }
        //@add:上一次設備為垂直擺放
        else {

            /*
            [self.coreImageContext drawImage:sourceImage inRect:CGRectMake(23.5, 123.5, 274, 274)
                                    fromRect:CGRectMake(23.5, 123.5, 274, 274)];
             */
            //@update: Tune UI
            [self.coreImageContext drawImage:sourceImage inRect:CGRectMake(23.5, 83.5, 274, 274)
                                    // x 越大, 濾鏡越向左; y 越多, 濾鏡越向上
                                    fromRect:CGRectMake(23.5, 83.5, 274, 274)];
        }
    }
}
....
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{   
    //@update
    // 設備垂直擺放
    if (interfaceOrientation == UIDeviceOrientationPortrait)
    {
        //[self.filterLensImageView setFrame:CGRectMake(20, 80, 280, 280)];
        //@update: Tune UI
        [self.filterLensImageView setFrame:CGRectMake(20, 120, 280, 280)];
    }
    // 設備垂直 180 度擺放
    else if (interfaceOrientation == UIDeviceOrientationPortraitUpsideDown) {
        //[self.filterLensImageView setFrame:CGRectMake(20, 80, 280, 280)];
        //@update: Tune UI
        [self.filterLensImageView setFrame:CGRectMake(20, 120, 280, 280)];
    }
    // 設備水平向右擺放
    else if (interfaceOrientation == UIDeviceOrientationLandscapeRight) {
        //[self.filterLensImageView setFrame:CGRectMake(80, 20, 280, 280)];
        //@update: Tune UI
        [self.filterLensImageView setFrame:CGRectMake(120, 20, 280, 280)];
    }
    // 設備水平向左擺放
    else if (interfaceOrientation == UIDeviceOrientationLandscapeLeft) {
        //[self.filterLensImageView setFrame:CGRectMake(80, 20, 280, 280)];
        //@update: Tune UI
        [self.filterLensImageView setFrame:CGRectMake(120, 20, 280, 280)];
    }
    // 其它 (UIDeviceOrientationFaceUp, UIDeviceOrientationFaceDown, UIDeviceOrientationUnknown)
    else {
        //[self.filterLensImageView setFrame:CGRectMake(80, 20, 280, 280)];
        //@update: Tune UI
        [self.filterLensImageView setFrame:CGRectMake(120, 20, 280, 280)];
    }
   
    return YES;
}
....

-------------------------------------------------------------------------------

C. 編譯並執行
     垂直擺放
     水平擺放(需要再調整)

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。