iphone - 将UIButton框架设置在UIImgeView的中心

标签 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 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/

相关文章:

iphone - 新 View Controller 中未调用按钮操作

ios - 如何使用台风快速注入(inject)委托(delegate)?

iphone - 防止 subview 在 UIScrollView 中滚动

ios - 我的 iPhone 3G 无法从 Xcode5 中选择为目标。这可以修复吗?

iphone - applicationWillEnterForeground 内存泄漏

iphone - writeImageToSavedPhotosAlbum 太慢?

ios - 模态视图 Controller subview

ios - 对持续触摸采取行动,而不是仅在触摸开始时采取行动 :

iphone - 无法使用 stackmob 作为后端找到英里内的位置

ios - Crashlytics 如何从 Carthage 框架上传 dsym 文件