How to set tablelist width for ipad? - uikit

I have a tablelist for iphone before:
#interface ListViewController : UITableViewController{
#end
And I plan to migrate to ipad target, but the width is still 320, how to change the width of ListViewController ?

Related

PresentViewController With ModalPresentationStyle "UIModalPresentationFormSheet" IOS 8

I am not able to set frame to PesentViewController with ModalPresentationStyle UIModalPresentationFormSheet in IOS 8. Same code works perfect in IOS 7. For all other ModalPresentationStyle, i am able to set frame. I am doing migration work from IOS 7 to IOS 8. If it is a IOS 8 bug i need a reference to produce.
FirstViewController *saleNotApprovedController = [[FirstViewController alloc]init];
saleNotApprovedController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:saleNotApprovedController animated:YES completion:^{
saleNotApprovedController.view.superview.frame = CGRectMake(100, 200, 500, 500);
}];
I tried to set frame in viewWillLayoutSubviews For PesentViewController. This code works while loading the page but when we change the orientation PesentViewController align to centre automatically.
Please use preferredContentSize to set view's frame.

iPad wrong [[UIScreen mainScreen] bounds].size dimensions

I don't know is this happening because of simulators or the new XCode, but I read that there is a solution for this. The solution is using a viewWillLayoutSubviews for creating the scene instead of viewDidLoad.
So I tried that, but that doesn't work. In landscape mode for iPad returned dimensions are always 768x1024 instead of 1024x768. Earlier, in XCode 5, viewWillLayoutSubviews did the trick. But now in XCode 6 I can't get that behaviour. I have this problem on 7.1 simulators. 8.0 simulators are just fine, and showing dimensions correctly.
Here is my GameSceneViewController.
#implementation GameViewController
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
skView.showsDrawCount = YES;
skView.showsPhysics = NO;
if(!skView.scene){
// Create and configure the scene.
GameScene * scene = [GameScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
}
- (BOOL)shouldAutorotate{return YES;}
- (NSUInteger)supportedInterfaceOrientations{return UIInterfaceOrientationMaskLandscape;}
- (void)didReceiveMemoryWarning{[super didReceiveMemoryWarning];}
- (BOOL)prefersStatusBarHidden {return YES;}
#end
In the info.plist file for supported interface oorientations are two items: UIInterfaceOrientationLandscapeRight and UIInterfaceOrientationLandscapeLeft
How can I get the correct sizes of a width and height in iPad landscape mode?
The screen size will always be the same regardless of device orientation. The same with the key window size. The view controllers are the ones that rotate inside the window. So you either rotate your view if you're adding it to the window directly or simply add it to the root view controller, which will have a correct size.
For example:
UIWindow* keyWindow = [UIApplication sharedApplication].keyWindow;
UIViewController* rootController = keyWindow.rootViewController;
CGSize screenSize = [UIScreen mainScreen].bounds.size;
CGSize windowSize = keyWindow.bounds.size;
CGSize rootControllerSize = rootController.view.frame.size;
CGSize rootControllerBoundsSize = rootController.view.bounds.size;
CGAffineTransform rootTransform = rootController.view.transform;
NSLog(#"Screen size: %#", NSStringFromCGSize(screenSize));
NSLog(#"Window size: %#", NSStringFromCGSize(windowSize));
NSLog(#"RootController frame size: %#", NSStringFromCGSize(rootControllerSize));
NSLog(#"RootController bounds size: %#", NSStringFromCGSize(rootControllerBoundsSize));
NSLog(#"RootController transform: %#", NSStringFromCGAffineTransform(rootTransform));
if executed in landscape will print the following:
Screen size: {768, 1024}
Window size: {768, 1024}
RootController frame size: {768, 1024}
RootController bounds size: {1024, 768}
RootController transform: [0, 1, -1, 0, 0, 0]
The key here is the transform that it's applied to the root UIViewController when the device is rotated.
To obtain the screen size taking into account the device rotation you can use the root controller bounds size.

Align UIView in the center of parent view by autoresizingMask in iOS 8

I have an app which is not using auto layout. Instead I'm using autoresizingMask. It works well in iOS 7. And it also works fine in iOS 8 when I start the app in portrait mode (it's still fine even when I rotate the device afterwards). Here is the screenshot when it's correct:
Here is my source code:
CGFloat w = [[UIScreen mainScreen]bounds].size.width;
CGFloat h = 100;
CGRect rect1 = CGRectMake(0, 0, w, h);
UIView* view1 = [[UIView alloc] initWithFrame:rect1];
view1.backgroundColor = [UIColor yellowColor];
view1.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:view1];
CGRect rect2 = CGRectMake(10, 105, 748, 50);
UIView* view2 = [[UIView alloc]initWithFrame:rect2];
view2.backgroundColor = [UIColor purpleColor];
view2.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:view2];
The problem occurs when I start my app in landscape mode. Here is the screenshot:
Can anybody tell what I did wrong in my code? Thanks
I modified the code a bit:
CGRect rect2 = CGRectMake((w-748)/2, 105, 748, 50);
This works as I expected.

SceneKit animation doesn't play in iOS

I have an example of animations fully working for OS X, start, pause, change speed etc.
Now I started porting this to iOS and can't even start the animation. I simplified the code to a minimum - it works in OS X, but not on iOS.
What I do is
Show a scene with a (animated) character in it (idle animation) - works both in OS X and iOS
Start a run animation on the character. This works on OS X, run animation starts and loops. On iOS the character is positioned at the start of run animation. But it doesn't run...
If I start with e.g. run scene instead of idle, it works - character runs. The problem is when I start an animation (any) after the scene is loaded. It loads the model with the animation but doesn't play.
After detailed comparison between the OS X and iOS version I found 2 differences, which probably are related but I can't figure out how fix them:
In the OS X version the character is not animated until I start an animation. In the iOS version when I attach the nodes from the idle (or whatever other) scene to the root, it's animated. I don't know how to change this.
The OS X version has the scene.dae attached to the Scene View in the Storyboard - this is also the case in iOS. But in iOS for some reason this attachment is not working, ´self.scene´ is nil. This is why I have to instantiate and assign the scene programmatically. I couldn't fix it, tried re-adding the Scene View, assigning the outlet etc.
The scene kit view is added using storyboard. idle and run are .dae files. Each of them contains a full model with the character, and the animation. I just double checked that the animation identifiers are the same as in the .dae files. The models are actually provided in an example from Apple and work perfectly on OS X...
This is the code:
View controller:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated {
[self.sceneView loadScene];
}
#end
Scene kit view header:
// ASCView.h
#import <UIKit/UIKit.h>
#import <SceneKit/SceneKit.h>
#interface ASCView : SCNView
- (void)loadScene;
#end
Scene kit view implementation:
//
// ASCView.m
// anim_test
//
//
#import "ASCView.h"
#implementation ASCView
- (void)loadScene {
self.backgroundColor = [UIColor blueColor];
self.allowsCameraControl = YES;
[self loadSceneAndAnimations];
}
#pragma mark - Animation loading
- (void)loadSceneAndAnimations {
// Load the character from one of our dae documents, for instance "idle.dae"
NSURL *idleURL = [[NSBundle mainBundle] URLForResource:#"idle" withExtension:#"dae"];
SCNScene *idleScene = [SCNScene sceneWithURL:idleURL options:nil error:nil];
SCNScene *scene = [SCNScene sceneNamed:#"scene.dae"];
self.scene = scene;
NSLog(#"scene: %#", self.scene);
// Merge the loaded scene into our main scene in order to
// place the character in our own scene
for (SCNNode *child in idleScene.rootNode.childNodes)
[self.scene.rootNode addChildNode:child];
// Load and start run animation
// The animation identifier can be found in the Node Properties inspector of the Scene Kit editor integrated into Xcode
[self loadAndStartAnimation:#"run" withIdentifier:#"RunID"];
}
- (void)loadAndStartAnimation:(NSString *)sceneName withIdentifier:(NSString *)animationIdentifier {
NSURL *sceneURL = [[NSBundle mainBundle] URLForResource:sceneName withExtension:#"dae"];
SCNSceneSource *sceneSource = [SCNSceneSource sceneSourceWithURL:sceneURL options:nil];
CAAnimation *animationObject = [sceneSource entryWithIdentifier:animationIdentifier withClass:[CAAnimation class]];
NSLog(#"duration: %f", [animationObject duration]); //0.9
animationObject.duration = 1.0;
animationObject.repeatCount = INFINITY;
[self.scene.rootNode addAnimation:animationObject forKey:#"foofoofoo"];
NSLog(#"animation: %#",[self.scene.rootNode animationForKey: #"foofoofoo"]);
NSLog(#"is paused: %#",[self.scene.rootNode isAnimationForKeyPaused: #"foofoofoo"] ? #"yes" : #"no"); //NO
}
#end
Ohh I found it. In iOS it seems I have to pass the options, in this case:
#{SCNSceneSourceAnimationImportPolicyKey:SCNSceneSourceAnimationImportPolicyPlayRepeatedly}
In OS X I don't - probably the defaults are different.

How we set the margin top,left margin of UITextField and UILabel for ios

How we set the margin top,left margin of UITextField and UILabel for ios. I am using this code for custom header of a table view.I want to top margin 28px and left margin 335px.
UILabel *sets = [[UILabel alloc] initWithFrame:CGRectMake(260, 10, 130, 20)];
sets.text = #"Sets";
sets.textColor=[UIColor colorWithRed:252.0/255 green:53.0/255.0 blue:55.0/255.0 alpha:1];
;
[sets setFont:[UIFont fontWithName:#"Helvetica neue Regular" size:6.0]];
sets.tag = 3;
[headerView addSubview:sets];
Set your frame to be CGRectMake(335.0, 28.0, your_width, your_height) and add the label as a subview of the header, just as your are now. Alternatively, you could create constraints.

Resources