Iphone 将UIButton框架设置在UIImgeView的中心
这是我要在中心设置的代码Iphone 将UIButton框架设置在UIImgeView的中心,iphone,ios,Iphone,Ios,这是我要在中心设置的代码 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
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];
我面临的问题是,当我改变按钮的方向时,它的位置会改变。它不会停留在中心。请帮忙
谢谢您需要处理这个问题。你所做的是正确的。当方向随着父视图的尺寸变化而变化时,需要对其进行调整。执行
willAnimateRotationInterfaceOrientation
delegate。看看这个-
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft||toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
//handle how you want to show in landscape mode
}
else
{
//handle how you want to show in portrait mode
}
}
你需要处理这件事。你所做的是正确的。当方向随着父视图的尺寸变化而变化时,需要对其进行调整。执行
willAnimateRotationInterfaceOrientation
delegate。看看这个-
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft||toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
//handle how you want to show in landscape mode
}
else
{
//handle how you want to show in portrait mode
}
}
其实你应该用这个方法
- (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;
}
其实你应该用这个方法
- (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;
}
你需要使用支柱和弹簧。检查uiview类的autoresizingMask属性。尝试使用videoImage.center=secondImageView.center我这样做了,但不起作用。您需要使用支柱和弹簧。检查uiview类的autoresizingMask属性。尝试使用videoImage.center=secondImageView.center我这样做了,但不起作用。我的imageview以特定角度旋转,现在我必须在该视图中添加按钮,该按钮也以相同角度旋转。我如何做到这一点?我没有更改我的图像的方向device@Srikar这个问题与旋转,而不是方向我的图像视图是以特定的角度旋转的,现在我必须在该视图中添加按钮,该按钮也以相同的角度旋转。我如何做到这一点?我没有改变图像的方向device@Srikar这个问题与轮换有关,而不是orientation@dimplepanchal这个问题与轮换有关,不orientation@dimplepanchal这个问题与旋转有关,而不是方向