Autolayout
is great. But at times you need to use a mixture of Storyboard and
programmatically generated UI code. In this case Autolayout can
overwrite your code settings. The trick is to use the following method:
viewDidLayoutSubviews gets called after it processes autolayout
constraints so if you need your UI code to take precedent, then you can
specify things here and your code will win over autolayout.
12. Random Loream Ipsum :
- (NSString *)randomLorumIpsum {
NSString *lorumIpsum = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent non quam ac massa viverra semper. Maecenas mattis justo ac augue volutpat congue. Maecenas laoreet, nulla eu faucibus gravida, felis orci dictum risus, sed sodales sem eros eget risus. Morbi imperdiet sed diam et sodales. Vestibulum ut est id mauris ultrices gravida. Nulla malesuada metus ut erat malesuada, vitae ornare neque semper. Aenean a commodo justo, vel placerat odio. Curabitur vitae consequat tortor. Aenean eu magna ante. Integer tristique elit ac augue laoreet, eget pulvinar lacus dictum. Cras eleifend lacus eget pharetra elementum. Etiam fermentum eu felis eu tristique. Integer eu purus vitae turpis blandit consectetur. Nulla facilisi. Praesent bibendum massa eu metus pulvinar, quis tristique nunc commodo. Ut varius aliquam elit, a tincidunt elit aliquam non. Nunc ac leo purus. Proin condimentum placerat ligula, at tristique neque scelerisque ut. Suspendisse ut congue enim. Integer id sem nisl. Nam dignissim, lectus et dictum sollicitudin, libero augue ullamcorper justo, nec consectetur dolor arcu sed justo. Proin rutrum pharetra lectus, vel gravida ante venenatis sed. Mauris lacinia urna vehicula felis aliquet venenatis. Suspendisse non pretium sapien. Proin id dolor ultricies, dictum augue non, euismod ante. Vivamus et luctus augue, a luctus mi. Maecenas sit amet felis in magna vestibulum viverra vel ut est. Suspendisse potenti. Morbi nec odio pretium lacus laoreet volutpat sit amet at ipsum. Etiam pretium purus vitae tortor auctor, quis cursus metus vehicula. Integer ultricies facilisis arcu, non congue orci pharetra quis. Vivamus pulvinar ligula neque, et vehicula ipsum euismod quis. Aliquam ut mi elementum, malesuada velit ac, placerat leo. Donec vel neque condimentum, congue justo a, posuere tortor. Etiam mollis id ligula nec dapibus. Etiam tincidunt, nisi non cursus adipiscing, enim neque tincidunt leo, vel tincidunt quam leo non ligula. Proin a felis tellus. Pellentesque quis purus est. Nam consectetur erat quam, non ultricies tortor venenatis ac. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Pellentesque at laoreet arcu. Mauris odio lorem, luctus facilisis ligula eget, malesuada pellentesque nulla.";
// Split lorum ipsum words into an array
//
NSArray *lorumIpsumArray = [lorumIpsum componentsSeparatedByString:@" "];
// Randomly choose words for variable length
//
int r = arc4random() % [lorumIpsumArray count];
NSArray *lorumIpsumRandom = [lorumIpsumArray objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, r)]];
// Array to string. Adding '!!!' to end of string to ensure all text is visible.
//
return [NSString stringWithFormat:@"%@!!!", [lorumIpsumRandom componentsJoinedByString:@" "]];
}
- (void)viewWillAppear:(BOOL)animated {
self.tableView.rowHeight = 76.0;
// Unselect the selected row if any
// http://forums.macrumors.com/showthread.php?t=577677
NSIndexPath* selection = [self.tableView indexPathForSelectedRow];
if (selection)
{
[self.tableView deselectRowAtIndexPath:selection animated:YES];
}
}
14. CGRectMake and NSStringFromCGRect :
How to NSLog the CGRect and CGFrame
CGRect rect1 = CGRectMake(100, 100, 100, 100);
CGRect rect2 = CGRectMake(190, 190, 100, 100);
NSLog(@"rect1: %@", NSStringFromCGRect(rect1));
NSLog(@"rect2: %@", NSStringFromCGRect(rect2));
CGSize size1 = CGSizeMake(100, 100);
CGSize size2 = CGSizeMake(190, 190);
NSLog(@"size1: %@", NSStringFromCGSize(size1));
NSLog(@"size2: %@", NSStringFromCGSize(size2));
-(BOOL)trimAudio {
// Path of your source LOCAL audio file
//NSString *strInputFilePath = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:@"MyAudioMemo.m4a"];
//NSURL *audioFileInput = [NSURL fileURLWithPath:strInputFilePath];
// Path of your source DocumentDirectory audio file
NSArray *pathComponents = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [pathComponents objectAtIndex:0];
NSString *strInputFilePath = [NSString stringWithFormat:@"%@%@",
documentsDirectoryPath,@"/MyAudioMemo.m4a"];
NSURL *audioFileInput = [NSURL fileURLWithPath:strInputFilePath];
// Path of your destination save audio file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask, YES);
NSString *libraryCachesDirectory = [paths objectAtIndex:0];
libraryCachesDirectory = [libraryCachesDirectory
stringByAppendingPathComponent:@"Caches"];
NSString *strOutputFilePath = [NSString stringWithFormat:@"%@%@",
libraryCachesDirectory,@"/abc.mp4"];
NSURL *audioFileOutput = [NSURL fileURLWithPath:strOutputFilePath];
if (!audioFileInput || !audioFileOutput)
{
return NO;
}
[[NSFileManager defaultManager] removeItemAtURL:audioFileOutput error:NULL];
AVAsset *asset = [AVAsset assetWithURL:audioFileInput];
AVAssetExportSession *exportSession = [AVAssetExportSession
exportSessionWithAsset:asset
presetName:AVAssetExportPresetAppleM4A];
if (exportSession == nil)
{
return NO;
}
NSLog(@"startTrimTime %f", startTrimTime);
NSLog(@"endTrimTime %f", endTrimTime);
float startTrimTime = 0;
float endTrimTime = 5;
CMTime startTime = CMTimeMake((int)(floor(startTrimTime * 100)), 100);
CMTime stopTime = CMTimeMake((int)(ceil(endTrimTime * 100)), 100);
CMTimeRange exportTimeRange = CMTimeRangeFromTimeToTime(startTime, stopTime);
exportSession.outputURL = audioFileOutput;
exportSession.outputFileType = AVFileTypeAppleM4A;
exportSession.timeRange = exportTimeRange;
[exportSession exportAsynchronouslyWithCompletionHandler:^
{
if (AVAssetExportSessionStatusCompleted == exportSession.status)
{
NSLog(@"Success!");
AVAudioPlayer *player = [[AVAudioPlayer alloc]
initWithContentsOfURL:audioFileOutput error:nil];
[player setDelegate:self];
[player play];
}
else if (AVAssetExportSessionStatusFailed == exportSession.status)
{
NSLog(@"failed");
}
}];
return YES;
}