0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
- (UIImage*)thumbnailImage:(NSString*)fileName:(BOOL)includeInCache
{
NSString *extension=@"png";
if(hasRetinaDisplay)
{
NSString *newFileName=[fileName stringByAppendingString:@"@2x"];
newFileName=[newFileName stringByAppendingFormat:@".%@", extension];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], newFileName]];
if(fileExists)
fileName=[fileName stringByAppendingString:@"@2x"];
}
fileName=[fileName stringByAppendingFormat:@".%@", extension];
UIImage *thumbnail = nil;
if(includeInCache)
thumbnail=[thumbnailCache objectForKey:fileName];
if (thumbnail == nil)
{
NSString *thumbnailFile = [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], fileName];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:thumbnailFile];
if(fileExists)
{
thumbnail = [UIImage imageWithContentsOfFile:thumbnailFile];
if(includeInCache)
[thumbnailCache setObject:thumbnail forKey:fileName];
}
}
return thumbnail;
}
велосипедище
diduz ,
06.08.2011 (Updated 25.03.2018 )
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
#define EmptyText @""
#define TextZero @"0"
#define TextOne @"1"
#define TextTwo @"2"
#define TextThree @"3"
#define TextFour @"4"
#define TextFive @"5"
#define TextSix @"6"
#define TextSeven @"7"
#define TextEight @"8"
#define TextNine @"9"
#define DigitZero 0
#define DigitOne 1
#define DigitTwo 2
#define DigitThree 3
#define DigitFour 4
#define DigitFive 5
#define DigitSix 6
#define DigitSeven 7
#define DigitEight 8
#define DigitNine 9
-(IBAction)DigitButtonClicked:(id)sender {
UIButton *button = (UIButton *)sender;
if ([digitLabel.text isEqualToString:TextZero]) {
if (button.tag == DigitOne) {
digitLabel.text = TextOne;
}
if (button.tag == DigitTwo) {
digitLabel.text = TextTwo;
}
if (button.tag == DigitThree) {
digitLabel.text = TextThree;
}
if (button.tag == DigitFour) {
digitLabel.text = TextFour;
}
if (button.tag == DigitFive) {
digitLabel.text = TextFive;
}
if (button.tag == DigitSix) {
digitLabel.text = TextSix;
}
if (button.tag == DigitSeven) {
digitLabel.text = TextSeven;
}
if (button.tag == DigitEight) {
digitLabel.text = TextEight;
}
if (button.tag == DigitNine) {
digitLabel.text = TextNine;
}
} else {
if (button.tag == DigitOne) {
digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitOne];
}
if (button.tag == DigitTwo) {
digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitTwo];
}
if (button.tag == DigitThree) {
digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitThree];
}
if (button.tag == DigitFour) {
digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitFour];
}
if (button.tag == DigitFive) {
digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitFive];
}
if (button.tag == DigitSix) {
digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitSix];
}
if (button.tag == DigitSeven) {
digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitSeven];
}
if (button.tag == DigitEight) {
digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitEight];
}
if (button.tag == DigitNine) {
digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitNine];
}
if (button.tag == DigitZero) {
digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitZero];
}
}
}
-(IBAction)DeleteButtonClicked {
if (![digitLabel.text isEqualToString:TextZero]) {
if (![digitLabel.text isEqualToString:EmptyText]) {
digitLabel.text = [ digitLabel.text substringToIndex:[digitLabel.text length] - 1 ];
if ([digitLabel.text length] == DigitZero) {
digitLabel.text = TextZero;
}
} else {
digitLabel.text = TextZero;
}
}
}
кусок кода, который по нажатой кнопке определяет что за цифра и добавляет ее в конец строки (или удаляет)...
контрол по типу калькулятора
olgerd ,
26.07.2011 (Updated 25.03.2018 )
0
1 2 3 4 5 6 7 8 9 10 11
if( (ori == UIInterfaceOrientationLandscapeLeft) || (ori == UIInterfaceOrientationLandscapeRight))
{
// Some code
}
else if(ori==UIInterfaceOrientationPortrait || ori==UIInterfaceOrientationPortraitUpsideDown)
{
// Some other code
}
else {
// God mode on!
}
Реальный проект после индусов... Что движет этими людьми я не понимаю...
makadaw ,
02.07.2011 (Updated 25.03.2018 )
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
NetworkStatus internet = [internetReachable currentReachabilityStatus];
switch (internet)
{
case NotReachable: { internetStatus = NO; break; }
case ReachableViaWiFi: { internetStatus = YES; break; }
case ReachableViaWWAN: { internetStatus = YES; break; }
default: break;
}
NetworkStatus host = [hostReachable currentReachabilityStatus];
switch (host)
{
case NotReachable: { hostStatus = NO; break; }
case ReachableViaWiFi: { hostStatus = YES; break; }
case ReachableViaWWAN: { hostStatus = YES; break; }
default: break;
}
//-------------------------------------------------------------
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return false;
}
//-------------------------------------------------------------
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if (logicRotate == 1)
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) // если ЛандскейпРайт
{
FlowCover.transform = CGAffineTransformIdentity;
indexLandscape = 1;
}
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) // если ЛандскейпЛефт
{
FlowCover.transform = CGAffineTransformMakeRotation(M_PI);
indexLandscape = 0;
}
}
else
{
if (indexLandscape == 1)
{
FlowCover.transform = CGAffineTransformIdentity;
}
else
{
FlowCover.transform = CGAffineTransformMakeRotation(M_PI);
}
logicRotate = 1;
}
return false;
}
//-------------------------------------------------------------
pagetextLabel.hidden = (pageFullScreen.realPageNo) ? NO : YES;
//-------------------------------------------------------------
[(FastImageView*)page showImage:[listOfImages objectAtIndex:pageIndex]]; //картинка
//-------------------------------------------------------------
if (firstPages>2) {
...
if (theAudio) {
[theAudio play]; //звук
}
firstPages++;
}
else
{
firstPages++;
}
//-------------------------------------------------------------
LabPercent.text = [NSString stringWithFormat:@"%d%@", percent * 100, @"%"];
//-------------------------------------------------------------
if ([DELEGATE isIPad]) {
mTempSize = [tempstr sizeWithFont:[UIFont fontWithName:@"Helvetica" size:17.0f] constrainedToSize:maxSize lineBreakMode:UILineBreakModeTailTruncation];
}
else {
mTempSize = [tempstr sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12.0f] constrainedToSize:maxSize lineBreakMode:UILineBreakModeTailTruncation];
}
h = mTempSize.height;
if ([DELEGATE isIPad]) {
lab.font = [UIFont fontWithName:@"Helvetica" size:17.0f];
}
else {
lab.font = [UIFont fontWithName:@"Helvetica" size:12.0f];
}
От того же автора http://govnokod.ru/6964 . Тут избранные куски, хотя можно постить весь проект
GLvRzZZ ,
17.06.2011 (Updated 25.03.2018 )
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
+ (NSUInteger)tagExpensiveCandyAnimationInteger:(NSUInteger)tagSprite
{
NSUInteger animationTag;
if(tagSprite == 2001)
{
animationTag = 2101;
}
else if(tagSprite == 2002)
{
animationTag = 2102;
}
else if(tagSprite == 2003)
{
animationTag = 2103;
}
else if(tagSprite == 2004)
{
animationTag = 2104;
}
else if(tagSprite == 2005)
{
animationTag = 2105;
}
else if(tagSprite == 2006)
{
animationTag = 2106;
}
else if(tagSprite == 2007)
{
animationTag = 2107;
}
else if(tagSprite == 2008)
{
animationTag = 2108;
}
else if(tagSprite == 2009)
{
animationTag = 2109;
}
else if(tagSprite == 2010)
{
animationTag = 2110;
}
else if(tagSprite == 2011)
{
animationTag = 2111;
}
else if(tagSprite == 2012)
{
animationTag = 2112;
}
return animationTag;
}
Того же автора:)
Chippman ,
16.06.2011 (Updated 25.03.2018 )
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if (rotateBag > 6) //после возврата, шудавторотейт вызывается 7 раз, это условие для погашения этих вызовов
{
if ([portret isEqualToString:@"horizontal"])
{
if (firstLaunch == 0) // блок для первого запуска (по умолчанию всегда выставляет ландскейпРайт, а это не всегда правильно)
{
if (interfacePosition == 0)
{ self.view.transform = CGAffineTransformMakeRotation(M_PI); }
else
{ self.view.transform = CGAffineTransformIdentity; }
firstLaunch++;
indexLandscape = interfacePosition;
}
else
{
if (indexLandscape == 1) //если изначальный вариант был правосторонний
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) // если ЛандскейпРайт
{ self.view.transform = CGAffineTransformIdentity;
interfacePosition = 1; }
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) // если ЛандскейпЛефт
{ self.view.transform = CGAffineTransformMakeRotation(M_PI);
interfacePosition = 0; }
}
else //если изначальный вариант был левосторонний
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) // если ЛандскейпРайт
{ self.view.transform = CGAffineTransformMakeRotation(M_PI);
interfacePosition = 1; }
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) // если ЛандскейпЛефт
{ self.view.transform = CGAffineTransformIdentity;
interfacePosition = 0; }
}
}
}
else
{
if (firstLaunch == 0) // блок для первого запуска (по умолчанию показывается правильно, поэтому ничего делать не надо)
{ firstLaunch++; }
else
{
if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{ self.view.transform = CGAffineTransformIdentity; }
if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{ self.view.transform = CGAffineTransformMakeRotation(M_PI); }
}
}
}
else {
rotateBag++;
}
return false;
}
Крутящаяся сумка в действии...
Поворот дисплея в 50 строк :\
mrWindMak3r ,
16.06.2011 (Updated 25.03.2018 )
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
if (starsCounter == 1)
{
[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(250, 190) z:1 tag:1];
}
else if (starsCounter == 2)
{
[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(250, 190) z:1 tag:1];
[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(260, 190) z:1 tag:1];
}
else if (starsCounter == 3)
{
[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(250, 190) z:1 tag:1];
[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(260, 190) z:1 tag:1];
[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(270, 190) z:1 tag:1];
}
else if (starsCounter == 4)
{
[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(250, 190) z:1 tag:1];
[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(260, 190) z:1 tag:1];
[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(270, 190) z:1 tag:1];
[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(280, 190) z:1 tag:1];
}
else if (starsCounter == 5)
{
[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(250, 190) z:1 tag:1];
[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(260, 190) z:1 tag:1];
[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(270, 190) z:1 tag:1];
[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(280, 190) z:1 tag:1];
[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(290, 190) z:1 tag:1];
}
Chippman ,
24.05.2011 (Updated 25.03.2018 )
0
1 2 3 4 5 6 7 8 9 10 11 12
public class XXX
{
private Object m_ForLock = new object();
private String m_Path = "";
public XXX(String Path)
{
lock (m_ForLock)
{
m_Path = Path;
}
}
}
BlackMonolit ,
15.04.2011 (Updated 25.03.2018 )
0
1 2 3 4 5 6 7 8 9 10 11 12 13
-(BOOL) checkIsDeleted:(Transactions*)target
{
if (target.transactionType == TransactionTypeTransfer)
{
if (target.cashFlow && target.cashFlow.isDeleted && target.secondCashFlow && target.secondCashFlow.isDeleted)
return YES;
return NO;
}
else
if (target.cashFlow && target.cashFlow.isDeleted)
return YES;
return NO;
}
Классика )))
Tika-Z ,
05.04.2011 (Updated 25.03.2018 )
0
1 2 3 4 5 6 7 8 9
/ set view controller
// this is just a pointer to object2
object1 = object2;
// claim ownership from object2
[object1 retain];
[object2 release];
This is all that is required. I have already tested & it works.
Пишем iPhone проект, боремся с мемори ликом, разработчик из индии (не учавствует в проекте) предлагает выход из положения с "вротмненоги" знанием дела
leon_coder ,
31.03.2011 (Updated 25.03.2018 )