在非结构或联合的东西中请求成员'子视图'?

时间:2014-08-11 18:32:43

标签: ios objective-c

我使用Quartz创建了一个渐变,只有一个问题。我无法通过屏幕旋转它。我已经尝试了this tutorial上列出的所有内容。这是视图控制器头:

#import <UIKit/UIKit.h>

@interface RadialGradientBackgroundViewController : UIViewController {

}

@end

这是视图控制器:

#import "RadialGradientBackgroundViewController.h"
#import "BackgroundLayer.h"

@implementation RadialGradientBackgroundViewController

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

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

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    CAGradientLayer *bgLayer = [BackgroundLayer gradient];
    bgLayer.frame = self.view.bounds;
    [self.view.layer insertSublayer:bgLayer atIndex:0];
}

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [[[self.subview.layer sublayers] objectAtIndex:0] setFrame:self.view.bounds]; // Error is here!
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

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

- (void)viewDidUnload {
}

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

@end

1 个答案:

答案 0 :(得分:1)

您的视图控制器没有subview属性或方法。在rmaddy said,将subview更改为view