How to show resized sidebar using SWRevealViewController? - ios

I am using SWRevealViewController in IOS app (universal). I'm getting sidebar in iPhone and iPad both but I want to show sidebar which covers 90% of screen - how can I?

open the SWRevealViewController.m file and then u get the _initDefaultProperties Method. in this method you get the side screen size and position
- (void)_initDefaultProperties
{
_frontViewPosition = FrontViewPositionLeft;
_rearViewPosition = FrontViewPositionLeft;
_rightViewPosition = FrontViewPositionLeft;
_rearViewRevealWidth = 260.0f; /// this is the method u change the side bar width
_rearViewRevealOverdraw = 60.0f;
_rearViewRevealDisplacement = 40.0f;
_rightViewRevealWidth = 260.0f;
_rightViewRevealOverdraw = 60.0f;
_rightViewRevealDisplacement = 40.0f;
_bounceBackOnOverdraw = YES;
_bounceBackOnLeftOverdraw = YES;
_stableDragOnOverdraw = NO;
_stableDragOnLeftOverdraw = NO;
_presentFrontViewHierarchically = NO;
_quickFlickVelocity = 250.0f;
_toggleAnimationDuration = 0.25;
_frontViewShadowRadius = 2.5f;
_frontViewShadowOffset = CGSizeMake(0.0f, 2.5f);
_frontViewShadowOpacity = 1.0f;
_userInteractionStore = YES;
_animationQueue = [NSMutableArray array];
_draggableBorderWidth = 0.0f;
}

Just have an if statement to determine the correct size of the sidebar. something like this:
if(device == iPad)
_rearViewRevealWidth = 600.0f;
else if(device == iPhone)
_rearViewRevealWidth = 260.0f;

open the SWRevealViewController.m file and then you get the _initDefaultProperties Method.
- (void)_initDefaultProperties
{
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
float x=(appDelegate.windowWidth)*9/10; //windowWidth=self.window.bounds.size.width;
float y=x-260;
_frontViewPosition = FrontViewPositionLeft;
_rearViewPosition = FrontViewPositionRightMost;
_rightViewPosition = FrontViewPositionLeft;
_rearViewRevealWidth = x;
_rearViewRevealOverdraw = 60.0f+y;
_rearViewRevealDisplacement = 40.0f+y;
....
}

You can do something like this...
When you have subclass from SWRevealViewController...
call property for this problem and set as you want...
Hope it's help someone...
self.rightViewRevealWidth = [UIScreen mainScreen].bounds.size.width * 0.9;

Related

How to fix SafeAreaLayoutGuide

I am making a game with canvas. The game is clipped because of the top notch, I've tried SafeAreaLayoutGuide but nothing happened. Please look at the code below and let me know what I am doing wrong.
-(void) createGLView {
//create our openglview and size it correctly
OpenGLView *glView = [[OpenGLView alloc] initWithFrame:self.appDelegate.initFrame];
self.view = glView;
self.appDelegate.canvas = glView;
core_init_gl(1);
glView.backgroundColor = [UIColor redColor];
glView.translatesAutoresizingMaskIntoConstraints = NO;
[glView.leadingAnchor constraintEqualToAnchor:glView.safeAreaLayoutGuide.leadingAnchor].active = YES;
[glView.trailingAnchor constraintEqualToAnchor:glView.safeAreaLayoutGuide.trailingAnchor].active = YES;
[glView.topAnchor constraintEqualToAnchor:glView.safeAreaLayoutGuide.topAnchor].active = YES;
[glView.bottomAnchor constraintEqualToAnchor:glView.safeAreaLayoutGuide.bottomAnchor].active = YES;
int w = self.appDelegate.screenWidthPixels;
int h = self.appDelegate.screenHeightPixels;
tealeaf_canvas_resize(w, h);
NSLOG(#"{tealeaf} Created GLView (%d, %d)", w, h);
}
The red color goes inside the top notch. I mean full screen. How to solve this?
You need to have a fullscreen parent view. Then you can add the OpenGLView as subview and connect its constraints to the parent view's safeAreaLayoutGuide.
- (void)createGLView {
OpenGLView *glView = [[OpenGLView alloc] initWithFrame:self.appDelegate.initFrame];
[self.view addSubview:glView];
self.appDelegate.canvas = glView;
core_init_gl(1);
glView.backgroundColor = [UIColor redColor];
glView.translatesAutoresizingMaskIntoConstraints = NO;
[glView.leadingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.leadingAnchor].active = YES;
[glView.trailingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor].active = YES;
[glView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor].active = YES;
[glView.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor].active = YES;
int w = self.appDelegate.screenWidthPixels;
int h = self.appDelegate.screenHeightPixels;
tealeaf_canvas_resize(w, h);
NSLOG(#"{tealeaf} Created GLView (%d, %d)", w, h);
}

Cocos2D v3 CCTableView not scrolling

I am trying to use a CCTableView in my game. You should be able to scroll through a list of names. I am able to click on a cell and log the which cell was clicked. However when I try to scroll there is no movement.
#interface WSMPlayerCandidateSubMenu(){
CCNodeColor *_candidateSubMenuSprite;
}
#implementation WSMPlayerCandidateSubMenu
- (void)onEnter{
[super onEnter];
CGSize winSize = [[CCDirector sharedDirector] viewSize];
_candidateSubMenuSprite.color = [CCColor whiteColor];
_candidateSubMenuSprite.userInteractionEnabled = NO;
self.candidateArray = [[WSMGameManager sharedManager] returnCompany].candidates;
CCTableView *tblScores = [CCTableView node];
tblScores.contentSize = CGSizeMake(1.0,0.8);
tblScores.anchorPoint = ccp(0.5f,0.375f);
tblScores.positionType = CCPositionTypeNormalized;
tblScores.position = _candidateSubMenuSprite.position;
tblScores.userInteractionEnabled = YES;
tblScores.dataSource = self;
tblScores.verticalScrollEnabled = YES;
tblScores.block = ^(CCTableView *table){
NSLog(#"Cell %ld", (long)table.selectedRow);
};
[_candidateSubMenuSprite addChild:tblScores];
}
-(CCTableViewCell*)tableView:(CCTableView *)tableView nodeForRowAtIndex:(NSUInteger)index{
CCTableViewCell* cell = [CCTableViewCell node];
cell.contentSizeType = CCSizeTypeMake(CCSizeUnitNormalized, CCSizeUnitPoints);
cell.contentSize = CGSizeMake(1, 40);
// Color every other row differently
CCNodeColor* bg = [CCNodeColor nodeWithColor:[CCColor colorWithRed:52/255.f green:73/255.f blue:94/255.f]];
bg.userInteractionEnabled = NO;
bg.contentSizeType = CCSizeTypeNormalized;
bg.contentSize = CGSizeMake(1, 1);
[cell addChild:bg];
WSMEmployee *candidate = (WSMEmployee*)[self.candidateArray objectAtIndex:index];
CCLabelTTF *lblCompanyName = [CCLabelTTF labelWithString:candidate.name fontName:#"ArialMT" fontSize:15.0f];
lblCompanyName.anchorPoint = ccp(1,0.5);
//lblTurnsSurvived.string = #"1000";
lblCompanyName.positionType = CCPositionTypeNormalized;
lblCompanyName.position = ccp(0.15,0.5);
lblCompanyName.color = [CCColor colorWithRed:242/255.f green:195/255.f blue:17/255.f];
[cell addChild:lblCompanyName];
return cell;
}
-(NSUInteger)tableViewNumberOfRows:(CCTableView *)tableView{
return [self.candidateArray count];
}
-(float)tableView:(CCTableView *)tableView heightForRowAtIndex:(NSUInteger)index{
return 40.f;
}
You need to set multipleTouchEnabled to YES on your instance of CCTableView. I had this same problem and that worked for me.

SetFrame Method doesn't work in ios8

I am using table view with dynamic height.
-(void)ShowTblRoomType
{
// [self.tableView_roomType setTranslatesAutoresizingMaskIntoConstraints:YES];
[self.tableView_roomType setFrame:CGRectMake(self.tableView_roomType.frame.origin.x, self.tableView_roomType.frame.origin.y, self.tableView_roomType.frame.size.width, self.tableView_roomType.rowHeight*self.roomtypeDetails.count)];
self.tableView_roomType.hidden = NO;
//set shadow to uitableview........
self.tableView_roomType.layer.masksToBounds = NO;
self.tableView_roomType.layer.cornerRadius = 8; // if you like rounded corners
self.tableView_roomType.layer.shadowOffset = CGSizeMake(-15, 20);
self.tableView_roomType.layer.shadowRadius = 3;
self.tableView_roomType.layer.shadowOpacity = 0.5;
}
From here I am calling this method
- (IBAction)showRoomTypeDetails:(id)sender
{
if(self.tableView_roomType.hidden == NO){
self.tableView_roomType.hidden = YES;
}else
{
[self ShowTblRoomType];
}
// [self.view_reservation bringSubviewToFront:self.tableView_roomType];
}
it works on below ios 8 but dosn't work on ios8.
on ios8 it shows only one cell.
Appreciate for help

UIKit Particle Systems in ios7. Number of particles increased

The particle system on ios7 seem to be working different, than on ios6 and ios5. The number of particles increased.
The same issue happens with all particle effects in the app.
The only working solution is to check, if it is ios7 and decrease the particle birth rate. Is there a better solution?
The code of particle emitter view.
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
//initialize the emitter
_emitter = (CAEmitterLayer*)self.layer;
_emitter.emitterPosition = CGPointMake(self.bounds.size.width /2, self.bounds.size.height/2 );
_emitter.emitterSize = self.bounds.size;
_emitter.emitterMode = kCAEmitterLayerAdditive;
_emitter.emitterShape = kCAEmitterLayerRectangle;
}
return self;
}
- (void)didMoveToSuperview
{
//Check if parent is initialized
[super didMoveToSuperview];
if (self.superview==nil) return;
//Load png
UIImage* texture = self.explosionImage; //[UIImage imageNamed:#"particle.png"];
NSAssert(texture, #"particle.png not found");
//Create a new emitter cell
CAEmitterCell* emitterCell = [CAEmitterCell emitterCell];
//Set the cell’s contents property to the texture you loaded
emitterCell.contents = (__bridge id)[texture CGImage];
//Name the cell “cell”
emitterCell.name = #"cell";
//Parameters
emitterCell.birthRate = self.birthRate;// 40;//1000
emitterCell.lifetime = 2.8;
emitterCell.lifetimeRange = 0.7;
//Set the cell’s color to randomly vary its components
if (!self.explosionColor) {
emitterCell.blueRange = 0.33;
emitterCell.blueSpeed = -0.33;
emitterCell.redRange = 0.33;
emitterCell.redSpeed = -0.33;
emitterCell.greenRange = 0.33;
emitterCell.greenSpeed = -0.33;
}
//Explosion color
if (self.explosionColor) emitterCell.color = [self.explosionColor CGColor];
//velocity
emitterCell.velocity = IS_IPAD?40:20;//160
emitterCell.velocityRange = RANDOMF(10, 20);//15
//Alpha
emitterCell.alphaSpeed = -0.73;
emitterCell.alphaRange = 0.9;
//Scale
emitterCell.scale = IS_IPAD?0.6:0.30;//0.5
emitterCell.scaleRange = 0.6;//0.5
emitterCell.scaleSpeed = 0;
//Range
emitterCell.emissionRange = M_PI*2;//2
//Add the cell to the emitter layer
_emitter.emitterCells = #[emitterCell];
[self performSelector:#selector(disableEmitterCell) withObject:nil afterDelay:self.cellIsEmitting];
[self performSelector:#selector(removeFromSuperview) withObject:nil afterDelay:self.emittingInView];
}
When running on an iOS7, it looks as if the particle system started animating earlier than the time the emitter layer is added.
It is probably a bug, and, hopefully, will be solved in future.
For now, to get a similar behavior as on iOS6, the CAEmitterLayer's beginTime can be set to the current time:
_emitter.beginTime = CACurrentMediaTime();

Show full screen on External Display for iOS

I just want to show full screen on External Display.
I'm using the code like this:
- (void) startTvOut {
NSArray *screens = [UIScreen screens];
CGSize max;
max.width = 0;
max.height = 0;
UIScreenMode *maxScreenMode = nil;
for (UIScreen *screen in screens)
{
if (screen != [UIScreen mainScreen])
{
for(int i = 0; i < [[screen availableModes] count]; i++)
{
UIScreenMode *current = [[screen availableModes] objectAtIndex: i];
if (current.size.width > max.width)
{
max = current.size;
maxScreenMode = current;
}
}
if (exWindow == nil)
{
exWindow = [[HUWindow alloc] initWithFrame:screen.brounds];
exWindow.backgroundColor = [UIColor whiteColor];
}
screen.overscanCompensation = UIScreenOverscanCompensationInsetBounds;
screen.currentMode = screen.preferredMode;
exWindow.screen = screen;
[exWindow makeKeyAndVisible];
m_isStarted = YES;
}
}
}
It can't show full screen on external device.
After I change the code
from
screen.overscanCompensation = UIScreenOverscanCompensationInsetBounds;
to
screen.overscanCompensation = UIScreenOverscanCompensationInsetApplicationFrame; it can show full screen, but the point (0,0) is not at the top of left screen.
My goal is to show the screen with full screen and have the point (0, 0) at the upper left corner of the screen. But it doesn't work.
Thanks in advance
Change this line:
screen.overscanCompensation = UIScreenOverscanCompensationInsetBounds;
to
screen.overscanCompensation = 3;
It's a non documented value...
For me the following code solved the problem (XCode 4, iOS 12.1)
screen.overscanCompensation = .scale
Before adding this line, I had the problem, that a black frame was around the screen.

Resources