【问题标题】:Help me to understand the answer given帮助我理解给出的答案
【发布时间】:2011-09-21 05:34:14
【问题描述】:

我在旋转设备时遇到了 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 逻辑,我想起了我用来在之间传递数据的一个方便的技巧 父/子视图控制器。

在您的反面视图控制器中,创建一个“rootViewController” 财产。在您的父视图控制器中,当您初始化 翻转视图控制器,您设置(其中“self”是 rootVC):

flipsideController.rootViewController = self;

然后您将其用于您的另一面 VC shouldAutorotateToInterfaceOrientation 方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 返回接口方向 == self.rootViewController.interfaceOrientation;

}

维奥拉!翻转视图不再在部分下方旋转 卷起父视图!

【问题讨论】:

  • 大概你从另一个 VC 中创建了一个 VC。您将指向创建 VC 的指针以您喜欢的任何名称(在本例中为 rootViewController)存储在创建的 VC 中,并且当您收到 shouldAutorotateToInterfaceOrientation: 调用时,您检查旋转是否与创建的 VC 相同。为此,您需要为创建的 VC 创建一个属性,例如 @property (nonatomic, assign) UIViewController *rootViewController; 和相应的实例变量。

标签: iphone ios4


【解决方案1】:

@来自帖子:在您的翻转视图控制器中,创建一个“rootViewController”属性。

#import <UIKit/UIKit.h>

@class ModalViewExampleViewController;

@interface flipSideViewController : UIViewController {

    ModalViewExampleViewController *rootViewController;

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

@end

在您的 FlipSideViewController 的实现文件中

#import "ModalViewExampleViewController.h"

@synthesize rootViewController;

【讨论】:

  • 您正在尝试将 ModalViewExampleViewController 实例分配给 rootViewController 实例,这会给您一个错误。 SampleViewController.rootViewController = self;如果您想要 ModalViewExampleViewController 属性,请将 FlipSideViewController 中的 rootViewController 更改为 ModalViewExampleViewController。
  • @Elanthiirayan :谢谢你的回复老兄..你能告诉我在源代码中我做错了什么吗。
  • 更新了我的代码,我的代码只会帮助你在另一个类中声明一个类的属性。请注意,要解决您的 curl 问题,您应该遵循您提到的答案。