这是我设置在中心的代码
UIButton *videoImage = [[UIButton alloc]initWithFrame:CGRectMake((secondImageView.frame.size.width/2)-50,(secondImageView.frame.size.height/2)-50,50,50)];
videoImage.transform = CGAffineTransformMakeRotation(ang*(3.14/180));
[videoImage setBackgroundImage:[UIImage imageNamed:@"PlayButton.png"] forState:UIControlStateNormal];
[videoImage addTarget:self action:@selector(PlayMusicOnClickofButton:) forControlEvents:UIControlEventTouchUpInside];
[secondImageView addSubview:videoImage];
videoImage.tag = k+1000;
secondImageView.userInteractionEnabled = YES;
[videoImage release];
我面临的问题是当我更改按钮的方向时它的位置被更改了。它不会保持居中。请帮忙
谢谢
最佳答案
实际上,您应该使用此方法。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
//handle how you want to show in landscape mode
}
else
{
//handle how you want to show in portrait mode
}
return YES;
}
关于iphone - 将UIButton框架设置在UIImgeView的中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8295120/