帮我理解给出的答案

问题描述:

我在旋转设备时遇到了UIModalTransitionStylePartialCurl问题,因为卷发不像我期望的那样旋转,我发现下面的答案摘录但我不能涂鸦。帮我理解给出的答案

我不知道如何创建一个“RootViewController的”房产作为向像下面

所以我期待你的指导做好进行进一步。我真的很坚持这个东西长天......

感谢您的帮助: -


的源代码我有

// 
// ModalViewExampleViewController.h 
// ModalViewExample 
// 
// Created by Tim Neill on 11/09/10. 
// 

#import <UIKit/UIKit.h> 

@interface ModalViewExampleViewController : UIViewController { 
    UIButton *showDefaultButton, *showFlipButton, *showDissolveButton, *showCurlButton; 
} 

@property (nonatomic, retain) IBOutlet UIButton *showDefaultButton, *showFlipButton, *showDissolveButton, *showCurlButton; 

- (IBAction)showDefault:(id)sender; 
- (IBAction)showFlip:(id)sender; 
- (IBAction)showDissolve:(id)sender; 
- (IBAction)showCurl:(id)sender; 

@end 

// 
// ModalViewExampleViewController.m 
// ModalViewExample 
// 
// Created by Tim Neill on 11/09/10. 
// 

#import "ModalViewExampleViewController.h" 
#import "SampleViewController.h" 

@implementation ModalViewExampleViewController 

@synthesize showDefaultButton, showFlipButton, showDissolveButton, showCurlButton; 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
} 

- (void)viewDidUnload { 
    [super viewDidUnload]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 

- (IBAction)showDefault:(id)sender { 
    SampleViewController *sampleView = [[[SampleViewController alloc] init] autorelease]; 
    [self presentModalViewController:sampleView animated:YES]; 
} 

- (IBAction)showFlip:(id)sender { 
    SampleViewController *sampleView = [[[SampleViewController alloc] init] autorelease]; 
    [sampleView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
    [self presentModalViewController:sampleView animated:YES]; 
} 

- (IBAction)showDissolve:(id)sender { 
    SampleViewController *sampleView = [[[SampleViewController alloc] init] autorelease]; 
    [sampleView setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; 
    [self presentModalViewController:sampleView animated:YES]; 
} 

- (IBAction)showCurl:(id)sender { 
    SampleViewController *sampleView = [[[SampleViewController alloc] init] autorelease]; 
    sampleView.rootViewController = self; 

    [sampleView setModalTransitionStyle:UIModalTransitionStylePartialCurl]; 
    [self presentModalViewController:sampleView animated:YES]; 
} 

- (void)dealloc { 
    [showDefaultButton release]; 
    [showFlipButton release]; 
    [showDissolveButton release]; 
    [showCurlButton release]; 
    [super dealloc]; 
} 
@end 

// 
// SampleViewController.h 
// ModalViewExample 
// 
// Created by Tim Neill on 11/09/10. 
// 

#import <UIKit/UIKit.h> 

@class RootViewController; 

@interface SampleViewController : UIViewController { 

    RootViewController *rootViewController; 

    UIButton *dismissViewButton; 
} 

@property (nonatomic, retain) IBOutlet UIButton *dismissViewButton; 

@property (nonatomic, retain) RootViewController *rootViewController; 


- (IBAction)dismissView:(id)sender; 

@end 

// 
// SampleViewController.m 
// ModalViewExample 
// 
// Created by Tim Neill on 11/09/10. 
// 

#import "SampleViewController.h" 


@implementation SampleViewController 

@synthesize rootViewController; 

@synthesize dismissViewButton; 

- (IBAction)dismissView:(id)sender { 
    [self dismissModalViewControllerAnimated:YES]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
} 

- (void)viewDidUnload { 
    [super viewDidUnload]; 
} 


- (void)dealloc { 
    [dismissViewButton release]; 
    [super dealloc]; 
} 


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    [self dismissModalViewControllerAnimated:YES]; 
    return YES; 
} 
@end 

UIView Animation: PartialCurl ...bug during rotate?

我也有这个问题,一定程度上放弃了。然而,我向一位朋友提到了我的 困境,他鼓励我研究儿童VC的 逻辑,并回想一下我用于在父/子视图控制器之间传递数据的便利技巧。

在你的flipside视图控制器中,创建一个“rootViewController” 属性。在你父视图控制器,当你初始化 另一面视图控制器,可以设置(其中,“自我”是rootVC):

flipsideController.rootViewController = self; 

然后,您可以使用此为您的另一面VC的 shouldAutorotateToInterfaceOrientation方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {return interfaceOrientation == self.rootViewController.interfaceOrientation;

}

Viola!翻转视图不再在部分旋转的父视图下旋转!

+0

想必你从另一个VC中创建VC。你可以使用你喜欢的任何名称(rootViewController)在创建的VC中存储一个指向创建VC的指针,当你收到一个shouldAutorotateToInterfaceOrientation:call时,你检查旋转是否与创建VC相同。 要做到这一点,你需要为创建VC创建一个属性,像'@property(nonatomic,assign)UIViewController * rootViewController;'和相应的实例变量。 – Baglan

@From帖子:在您的另一面视图控制器,创建一个 “RootViewController的” 属性。

#import <UIKit/UIKit.h> 

@class ModalViewExampleViewController; 

@interface flipSideViewController : UIViewController { 

    ModalViewExampleViewController *rootViewController; 

} 
@property (nonatomic, retain) ModalViewExampleViewController *rootViewController; 

@end 

,并在您flipSideViewController的实现文件

#import "ModalViewExampleViewController.h" 

@synthesize rootViewController; 
+0

您正尝试将一个ModalViewExampleViewController实例分配给rootViewController实例,该实例会给您一个错误。 SampleViewController。rootViewController = self;如果您想要ModalViewExampleViewController属性,请将flipSideViewController中的rootViewController更改为ModalViewExampleViewController。 – sElanthiraiyan

+0

@Elanthiirayan:谢谢你的回复。你可以告诉我,在源代码中我做错了。 – user198725878

+0

更新了我的代码,我的代码只会帮助您在另一个类中声明一个类的属性。请注意,要解决你的卷曲问题,你应该按照你提到的答案。 – sElanthiraiyan