开发者

how can i change orientation by button's click events?

开发者 https://www.devze.com 2022-12-18 09:09 出处:网络
I have used TableView and also used Disclosure Button by 开发者_Go百科clicking onDisclosure Button i have got one Particular Image comes.i want that when i pressedDisclosure Button i have to get that

I have used TableView and also used Disclosure Button by 开发者_Go百科clicking on Disclosure Button i have got one Particular Image comes.i want that when i pressed Disclosure Button i have to get that particular image with performing Orientation so how can i do it.please help me. I am new in this kind of application.


You need to manually transform the table. Here is some code to create and rotate a UITableView around its center.

// this defines a constant PORTRAIT_FRAME, which is the frame of the iPhone screen 
// minus the Status Bar. Equivalent to CGRectMake(0,20,320,460). 
#define PORTRAIT_FRAME [[UIScreen mainScreen] applicationFrame]

// this defines a constant LANDSCAPE_FRAME, for orienting the table sideways
#define LANDSCAPE_FRAME CGRectMake(0,20,480,300)


// this function assumes you have a class variable called myTableView
// and it toggles the orientation of myTableView
- (void) rotateTable {

  if (myTableView.transform == CGAffineTransformMakeRotation(0)) {
    // rotate the image by 90 degrees  
    myTableView.transform = CGAffineTransformMakeRotation(M_PI/2); 
    myTableView.frame = LANDSCAPE_FRAME;
    return;
  }

  // set the image to its original orientation 
  myTableView.transform = CGAffineTransformMakeRotation(0); 
  myTableView.frame = PORTRAIT_FRAME;

}

If you want to trigger this rotation on a button click, then declare a UIButton and assign this function as the action. Here's a function to create a UIButton. Just pass it @"rotateImage" for the action and self for the target.

+ (UIButton*) getButtonAtPoint:(CGPoint)point 
                             target:(id)target 
                             action:(NSString*)action {

  UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
  [button addTarget:target 
             action:NSSelectorFromString(action)
   forControlEvents:UIControlEventTouchUpInside];
  return button;
}


I think you may need to use UIApplication's setStatusBarOrientation:animated: and rotate/resize your top level view manually. If you use UIView's animation block methods then you should just be able to do this inside an animation block and commit it to get essentially the same effect. Haven't tried this myself though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号