2010-12-20 56 views
13

我想知道是否有方法可以將我的視圖轉換爲iPhone文件夾。換句話說,我希望我的視角在中間的某個位置分開,並在其下方顯示一個視圖。這可能嗎?如何製作類似iPhone文件夾的東西?

alt text

編輯: 每下面的建議,我可以把我的應用程序的截圖通過這樣做:

UIGraphicsBeginImageContext(self.view.bounds.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

不知道但是怎麼做這個。

編輯:2 我已經想通了如何一些陰影添加到我的觀點,這裏是我所取得的成就(冒出顯示相關部分):

alt text

編輯:3

http://github.com/jwilling/JWFolders

+0

ahhh好,我在cocoacontrols.com上找到了你我的好人^^。開源FTW! =) – 2013-02-03 19:58:27

+0

的確如此。感謝您幫助我從頭開始。 ;) – 2013-02-03 19:59:37

+0

你可以看看'OGActionChooser';)但是它似乎目前有服務器問題:( – 2013-02-03 20:03:40

回答

6

的基本思想將是把你的小人的圖片租用國家並將其分開。然後通過設置一個新的框架爲兩個部分設置動畫。我不知道如何採取截圖編程,所以我不能提供的示例代碼...

編輯:嘿它不看大,但它的工作原理^^

// wouldn't be sharp on retina displays, instead use "withOptions" and set scale to 0.0 
// UIGraphicsBeginImageContext(self.view.bounds.size); 
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0.0); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *f = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

CGRect fstRect = CGRectMake(0, 0, 320, 200); 
CGRect sndRect = CGRectMake(0, 200, 320, 260); // was 0,200,320,280 


CGImageRef fImageRef = CGImageCreateWithImageInRect([f CGImage], fstRect); 
UIImage *fCroppedImage = [UIImage imageWithCGImage:fImageRef]; 
CGImageRelease(fImageRef); 

CGImageRef sImageRef = CGImageCreateWithImageInRect([f CGImage], sndRect); 
UIImage *sCroppedImage = [UIImage imageWithCGImage:sImageRef]; 
CGImageRelease(sImageRef); 


UIImageView *first = [[UIImageView alloc]initWithFrame:fstRect]; 
first.image = fCroppedImage; 
//first.contentMode = UIViewContentModeTop; 
UIImageView *second = [[UIImageView alloc]initWithFrame:sndRect]; 
second.image = sCroppedImage; 
//second.contentMode = UIViewContentModeBottom; 

UIView *blank = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)]; 
blank.backgroundColor = [UIColor darkGrayColor]; 

[self.view addSubview:blank]; 
[self.view addSubview:first]; 
[self.view addSubview:second]; 

[UIView animateWithDuration:2.0 animations:^{ 
    second.center = CGPointMake(second.center.x, second.center.y+75); 
}]; 

您可以取消這兩個.contentMode線條和質量會提高,但在我的情況下,子視圖的偏移量爲10px左右(可以通過爲兩個子視圖設置背景顏色來看到它)

//編輯2:ok找到該錯誤。已經使用了整個320x480的屏幕,但不得不切斷狀態欄,所以它應該是320x460,並且所有的都很好;)

+0

這可能工作......我只是不知道如何分割它 – 2010-12-20 21:16:53

+0

我認爲CoreGraphics或Cocos2d應該工作但如果您可以指定要捕捉的區域,或者如果您將使用UIImageView,則可以更簡單地進行截圖,您可以將自動調整大小設置爲始終保持在頂部/底部角落,然後稍微切掉一幀 – 2010-12-20 21:19:50

+0

謝謝對於你的辛勤工作,它看起來不錯,在做完這個之後我該如何回到主視圖? – 2010-12-20 22:23:43

2

而不是拍攝視圖的快照,您可以使用單獨的視圖爲圖標。你需要做更多的工作來重新定位東西,但是當文件夾打開時這些行不會是靜態的(換句話說,它們會根據需要繼續重繪)。

+0

Dave,感謝您的評論!我其實並不想要這些圖標(應該在我的回答中予以澄清),但我只是想將視圖分解成一半。 – 2010-12-21 16:55:59

1

我把relikd's代碼作爲基礎,使它更具動感。

您可以在調用函數時指定分割位置和方向,並向分割圖像添加邊框。

#define splitAnimationTime 0.5 
- (void)split:(SplitDirection)splitDirection 
atYPostition:(int)splitYPosition 
withRevealedViewHeight:(int)revealedViewHeight{ 

    // wouldn't be sharp on retina displays, instead use "withOptions" and set scale to 0.0 
    // UIGraphicsBeginImageContext(self.view.bounds.size); 
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0.0); 
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *f = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    CGRect fullScreenRect = [self getScreenFrameForCurrentOrientation]; 

    CGRect upperSplitRect = CGRectMake(0, 0,fullScreenRect.size.width, splitYPosition); 
    CGRect lowerSplitRect = CGRectMake(0, splitYPosition, fullScreenRect.size.width, fullScreenRect.size.height-splitYPosition); 


    CGImageRef upperImageRef = CGImageCreateWithImageInRect([f CGImage], upperSplitRect); 
    UIImage *upperCroppedImage = [UIImage imageWithCGImage:upperImageRef]; 
    CGImageRelease(upperImageRef); 

    CGImageRef lowerImageRef = CGImageCreateWithImageInRect([f CGImage], lowerSplitRect); 
    UIImage *lowerCroppedImage = [UIImage imageWithCGImage:lowerImageRef]; 
    CGImageRelease(lowerImageRef); 


    UIImageView *upperImage = [[UIImageView alloc]initWithFrame:upperSplitRect]; 
    upperImage.image = upperCroppedImage; 
    //first.contentMode = UIViewContentModeTop; 

    UIView *upperBoarder = [[UIView alloc]initWithFrame:CGRectMake(0, splitYPosition, fullScreenRect.size.width, 1)]; 
    upperBoarder.backgroundColor = [UIColor whiteColor]; 
    [upperImage addSubview:upperBoarder]; 


    UIImageView *lowerImage = [[UIImageView alloc]initWithFrame:lowerSplitRect]; 
    lowerImage.image = lowerCroppedImage; 
    //second.contentMode = UIViewContentModeBottom; 

    UIView *lowerBoarder = [[UIView alloc]initWithFrame:CGRectMake(0, 0, fullScreenRect.size.width, 1)]; 
    lowerBoarder.backgroundColor = [UIColor whiteColor]; 
    [lowerImage addSubview:lowerBoarder]; 

    int reveledViewYPosition = splitYPosition; 

    if(splitDirection==SplitDirectionUp){ 
     reveledViewYPosition = splitYPosition - revealedViewHeight; 
    } 


    UIView *revealedView = [[UIView alloc]initWithFrame:CGRectMake(0, reveledViewYPosition, fullScreenRect.size.width, revealedViewHeight)]; 
    revealedView.backgroundColor = [UIColor scrollViewTexturedBackgroundColor]; 


    [self.view addSubview:revealedView]; 
    [self.view addSubview:upperImage]; 
    [self.view addSubview:lowerImage]; 

    [UIView animateWithDuration:splitAnimationTime animations:^{ 
     if(splitDirection==SplitDirectionUp){ 
      upperImage.center = CGPointMake(upperImage.center.x, upperImage.center.y-revealedViewHeight); 
     } else { //assume down 
      lowerImage.center = CGPointMake(lowerImage.center.x, lowerImage.center.y+revealedViewHeight); 
     } 
    }]; 
} 

這意味着我可以這樣調用:

[self split:SplitDirectionUp atYPostition:500 withRevealedViewHeight:200]; 

我在更新後的分割功能使用這些爲了方便地使用功能:

- (CGRect)getScreenFrameForCurrentOrientation { 
    return [self getScreenFrameForOrientation:[UIApplication sharedApplication].statusBarOrientation]; 
} 

- (CGRect)getScreenFrameForOrientation:(UIInterfaceOrientation)orientation { 

    UIScreen *screen = [UIScreen mainScreen]; 
    CGRect fullScreenRect = screen.bounds; 
    BOOL statusBarHidden = [UIApplication sharedApplication].statusBarHidden; 

    //implicitly in Portrait orientation. 
    if(orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft){ 
     CGRect temp = CGRectZero; 
     temp.size.width = fullScreenRect.size.height; 
     temp.size.height = fullScreenRect.size.width; 
     fullScreenRect = temp; 
    } 

    if(!statusBarHidden){ 
     CGFloat statusBarHeight = 20; 
     fullScreenRect.size.height -= statusBarHeight; 
    } 

    return fullScreenRect; 
} 

與此枚舉:

typedef enum SplitDirection 
{ 
    SplitDirectionDown, 
    SplitDirectionUp 
}SplitDirection; 

將回歸添加到常規f聯合和增加箭頭將是一個很好的補充。

+1

你可能有興趣看到我剛纔寫的一個圖書館,它包裝了所有這些。 https://github.com/jwilling/JWFolders – 2013-01-27 18:52:34

+0

哈,謝謝。希望這是在我開始之前在這裏! – 2013-01-28 00:15:15

+0

嘿耶,對不起,我應該發佈它。在這裏,有一個安慰。 :) – 2013-01-28 00:47:57

相關問題