Iphone UIImage未在视图中加载未在iOS中加载
当我加载应用程序时,按钮图像不是在Iphone UIImage未在视图中加载未在iOS中加载,iphone,ios,uibutton,uiimage,Iphone,Ios,Uibutton,Uiimage,当我加载应用程序时,按钮图像不是在viewDidLoad的第一个视图中加载的,而是在视图之后加载的 这是我的密码 if (activityorientation == UIInterfaceOrientationPortrait || activityorientation == UIInterfaceOrientationPortraitUpsideDown) { CGRect frameloginscreenbutton1 = CGRectMake(0, 0, 768,1004);
viewDidLoad
的第一个视图中加载的,而是在视图之后加载的
这是我的密码
if (activityorientation == UIInterfaceOrientationPortrait || activityorientation == UIInterfaceOrientationPortraitUpsideDown)
{
CGRect frameloginscreenbutton1 = CGRectMake(0, 0, 768,1004);
[loginscreenbutton1 setFrame:frameloginscreenbutton1];
}
else if(activityorientation == UIInterfaceOrientationLandscapeLeft || activityorientation == UIInterfaceOrientationLandscapeRight)
{
CGRect frameloginscreenbutton1 = CGRectMake(0, 0, 1024,768);
[loginscreenbutton1 setFrame:frameloginscreenbutton1];
}
有什么指示吗?我想是因为没有创建“是”之类的东西
您可以使用此方法在零延迟后在viewdidload中设置帧
- (void)viewDidLoad
{
[super viewDidLoad];
[self performSelector:@selector(setButtonFrame) withObject:nil afterDelay:0];
}
-(void) setButtonFrame
{
//your code
}
如果不起作用,请尝试Xmple 0.1的其他延迟,这在某种程度上取决于按钮是否从nib加载。如果它是从nib加载的,则在调用viewDidLoad
时它不存在。您可以使用断点自己验证这一点。当viewdide出现时:
被调用,它已经被创建
如果要配置从Interface Builder(无论是从xib文件还是故事板)加载的项目,则正确的时间是通过重写按钮的代码(如果(activityorientation==UIInterfaceOrientationRotatic | | activityorientation==UIInterfaceOrientationGraphitoUpsideDown){CGRect frameloginscreenbutton1=CGRectMake(0,07681004);[loginscreenbutton1 setFrame:frameloginscreenbutton1];}如果(activityorientation==ui接口方向和scapeleft | | activityorientation==ui接口方向和scaperight){CGRect frameloginscreenbutton1=CGRectMake(0,020247668);[loginscreenbutton1 setFrame:frameloginscreenbutton1];}@user968597请通过编辑添加问题中的代码。实际上,当应用程序运行iPad 1时,它会显示按钮图像。但当应用程序运行iPad 2时,它不会显示按钮图像