简体   繁体   English

方向上的旋转按钮更改为横向视图

[英]Rotate Button On Orientation Changed to Landscape View

I am making one Paint application..The button marked with Red circle, I want it to be rotated 90 degree "when orientation is changed to Landscape mode".. Image marked with RED circle is placed on BUTTON.. So should i rotate button or image when orientation changes??我正在制作一个油漆应用程序..标有红色圆圈的按钮,我希望它旋转 90 度“当方向更改为横向模式时”.. 标有红色圆圈的图像放置在按钮上.. 所以我应该旋转按钮或方向改变时的图像?

Hope this description will give you idea about my problem.. Thanks..希望这个描述能让你了解我的问题..谢谢..

Please follow this link to see screenshot as i am not allowed to post image..请点击此链接查看屏幕截图,因为我不允许发布图像..

http://imageshack.us/photo/my-images/26/screenshot20110712at507.png/ http://imageshack.us/photo/my-images/26/screenshot20110712at507.png/

You could do either but I think it would be easier to just flip the image 90 degrees.你可以做任何一个,但我认为将图像翻转 90 度会更容易。 When your application switches to landscape have a new image, really just the old image turned 90 degrees, and set that as the image for the button.当您的应用程序切换到横向时,有一个新图像,实际上只是将旧图像转了 90 度,并将其设置为按钮的图像。 Hope this helps.希望这可以帮助。

Well thats a sweet deal.嗯,这是一个甜蜜的交易。 Just copy paste the follwing code in your view controller (the one in which you want the buttons to be rotated).只需将以下代码复制粘贴到您的视图 controller (您希望在其中旋转按钮的代码)。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationPortrait ||
    interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
    interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    return YES;
else {
    return NO;
}}

This might give you the idea of your target.这可能会让你知道你的目标。 Happy Coding..!快乐编码..!

You can set the frame of UIButton in the following method as follows:您可以通过以下方法设置 UIButton 的框架,如下所示:

In.h class在.h class

IBOutlet UIButton *redButton;

And in.m class:和 in.m class:

  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
         if (interfaceOrientation == UIInterfaceOrientationPortrait)
         {
             redButton.frame = CGRectMake(100,50,100,50)
         }
         else 
         {
             redButton.frame = CGRectMake(50,100,100,50)
         }

   return YES;

    }

So, you can change the frame of your button as per the requirement.因此,您可以根据需要更改按钮的框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM