gpt4 book ai didi

ios - 请求非结构或联合中的成员 'subview'?

转载 作者:行者123 更新时间:2023-11-29 02:45:03 24 4
gpt4 key购买 nike

我使用 Quartz 创建了一个渐变,只有一个问题。我无法让它随屏幕旋转。我已经尝试了 this tutorial 上列出的所有内容。这是 View Controller header :

#import <UIKit/UIKit.h>

@interface RadialGradientBackgroundViewController : UIViewController {

}

@end

这是 View Controller :

#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

最佳答案

您的 View Controller 没有 subview 属性或方法。作为rmaddy said , 将 subview 更改为 view.

关于ios - 请求非结构或联合中的成员 'subview'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25250060/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com