小编Vla*_*mir的帖子

CATiledLayer绘图崩溃

在我的应用程序中,我使用了以下视图层次结构:

UIView
----UIScrollView
--------TiledView (UIView subclass, uses CATiledLayer for drawing)
----OverlayView (UIView subclass)
Run Code Online (Sandbox Code Playgroud)

简而言之 - TiledView显示大平铺图像我也将自定义旋转应用于该视图:

tiledView.transform = CGAffineTransformMakeRotation(angle);
Run Code Online (Sandbox Code Playgroud)

TiledView的绘图方法:

- (void)drawRect:(CGRect)rect {
    // Drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();  
    ...
  NSString *fileName = [NSString stringWithFormat:@"tile_%d_%d.jpg", y + 1, x + 1];
    UIImage *image = [UIImage imageNamed:fileName];
    [image drawInRect:rect];
 }
Run Code Online (Sandbox Code Playgroud)

UIScrollView允许滚动和缩放其内容.
叠加视图覆盖UIScrollView,具有透明背景并执行一些自定义绘图.我使用单独的视图来确保线条宽度和字体大小不受滚动视图中缩放比例的影响.

OverlayView的绘图方法:

- (void)drawRect:(CGRect)rect {
    // Drawing code
    [super drawRect:rect];

    // Custom drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 0, 1);
   CGContextSetLineWidth(context, lineWidth);

    CGContextBeginPath(context);
    CGContextMoveToPoint(context, (int)startPoint.x,(int) …
Run Code Online (Sandbox Code Playgroud)

iphone crash drawing uiview catiledlayer

1
推荐指数
1
解决办法
4173
查看次数

用数组求sum,min,max

编写一个输入数值的程序,然后在循环中逐个输入这些值(双精度型),最后输出它们的和,最大值和最小值.

我为这个作业编写了代码,但是我收到了错误

#include <stdio.h>

int main(void)
{
        float a;
        float i;
        short c;
        float sum;
        float nu[];

        i=nu[];

          printf("Number of values :");
          scanf("%f",&i);

        for (c=1;i>=c;c++)
        {
          printf("values=");
          scanf("%f",&nu[c]);

                sum = sum + nu[c];
        //      printf("Sum = %f\n",sum);
        }

        printf("sum = %f \n",sum);
//      printf("Number of values :");
//      scanf("%f",&i);
}
Run Code Online (Sandbox Code Playgroud)

错误是number.c:在函数'main'中:number.c:9:错误:'nu'number.c中缺少数组大小:11:错误:']'令牌之前的预期表达式

c

1
推荐指数
1
解决办法
4881
查看次数

override isEqual Objective-C

我的课

@interface sample:NSObject{

   double x;

   double y;

}
@property double x;

@property double y;

-(sample *)initWithX: (double)x andY:(double) Y;


@implementation

@synthesize x,y

-(sample *) initWIthX: (double)x andY:(double)y{

    self = [super init];

    if(self) 
    {

      self.x = x;

      self.y = y; 

    }
     return self;

}

-(BOOL)isEqual:(id)other{

 if(other == self)
   return YES;
 if(!other || ![other isKindOfClass:[self class]])
   return NO;
 return [self isEqualToSample:other];  
}


-(BOOL)isEqualToSample:(sample *) other{

 if(self == other)    
   return YES;

 if (!([self x] ==[other x])) 
   return NO;

 if (!([self y] ==[other y])) …
Run Code Online (Sandbox Code Playgroud)

objective-c

1
推荐指数
1
解决办法
2752
查看次数

如何将数据添加到UITableView?

如何将数据添加到UITableView?我需要在此视图中插入数据数组

UITableView *tableView = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStylePlain];
[table numberOfRowsInSection:20];
table.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uitableview

1
推荐指数
1
解决办法
1万
查看次数

与MKAnnotation图像属性的问题

我正在实现一个基于MKMapView的应用程序.在那里我使用自定义图像而不是通过使用MKAnnotationView.Image属性显示一个引脚.它不起作用.它一直显示标准引脚为红色,但不是我指向的图像.有任何想法吗?

- (void)setPin:(MKPinAnnotationView *)aPin forAnnotation:(id <MKAnnotation>)anAnnotation {
    if (anAnnotation == self.userAnnotation) {

        aPin.image = [UIImage imageNamed:@"youarehere.png"];
        aPin.opaque = NO;

        aPin.pinColor = MKPinAnnotationColorRed;
    }
}
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch mkannotation mkannotationview

1
推荐指数
1
解决办法
1442
查看次数

方法可能无法回应

在一个类(名为TimeDetails)中,我需要调用一个方法(类方法),但在编译期间我收到此消息:TimesDetails可能不响应'generateTimeOfPassage',(一个方法调用另一个方法并发送一个NSString对象.这种情况返回nil).

在.h文件中我声明了这样的方法:

+(NSString *)generateTimeOfPassage:(NSString *)_timeString;
Run Code Online (Sandbox Code Playgroud)

在.m文件中:

-(void)initWithTimeData:(NSString *)_timeString{
    [super init];
    passage=[self generateTimeOfPassage:_timeString]; ---I have the message here...
}
+(NSString *)generateTimeOfPassage:(NSString *)_timeString{

    return nil;
} 
Run Code Online (Sandbox Code Playgroud)

谢谢 !

马克西姆

iphone objective-c

1
推荐指数
1
解决办法
186
查看次数

无法对整数数组进行排序?

我想按升序对多个数字的整数数组进行排序.

这是我的数组:

keyArray:
(
   978,
   1077,
   1067,
   1076,
   1072,
   1082,
   1079,
   1075,
   1071,
   1081,
   1078,
   1080,
   1074
Run Code Online (Sandbox Code Playgroud)

)

这是我的代码:

NSSortDescriptor *sortOrder = [NSSortDescriptor sortDescriptorWithKey:@"self"  ascending: YES];

NSArray *sortedArray2 = [keyArray sortedArrayUsingComparator:^(id str1, id str2) {

    if ([str1 integerValue] < [str2 integerValue]) {
        return (NSComparisonResult)NSOrderedDescending;
    }

    if ([str1 integerValue] > [str2 integerValue]) {
        return (NSComparisonResult)NSOrderedAscending;
    }
    return (NSComparisonResult)NSOrderedSame;
}];

NSLog(@"%@",[keyArray sortedArrayUsingDescriptors: [NSArray arrayWithObject:sortOrder]]);
Run Code Online (Sandbox Code Playgroud)

问题是,这会像这样对数组进行排序

sortedArray: (

  1067,
  1071,
  1072,
  1074,
  1075,
  1076,
  1077,
  1078,
  1079,
  1080,
  1081,
  1082,
  978
)
Run Code Online (Sandbox Code Playgroud)

它将首先对四位数字进行排序,然后对三位数字进行排序.

iphone objective-c

1
推荐指数
1
解决办法
1886
查看次数

使用块时"与整数转换不兼容"

我正在为下面的代码收到这些警告.任何想法如何解决?谢谢你的帮助.

  • 类型说明符缺失,默认为'int'
  • 指向整数转换的指针不兼容,使用'void*'类型的表达式初始化'int';
  • 未使用的变量'mymoviePlayerController'

重要的是 "__block mymoviePlayerController = nil;

- (void) moviePlaybackCompleteLightBox:(NSNotification*) notification {

        MPMoviePlayerController *mymoviePlayerController = [notification object];  
        [[NSNotificationCenter defaultCenter] removeObserver:self  
                                                        name:MPMoviePlayerPlaybackDidFinishNotification  
                                                      object:mymoviePlayerController]; 


        // movie fadein transition ====================
        self.moviePlayerController.view.alpha = 1;

        [UIView animateWithDuration:0.3f delay:0.0 options:UIViewAnimationCurveEaseOut
                         animations:^{
                             self.moviePlayerController.view.alpha = 0;   
                         }
                         completion:^(BOOL finished) { 
                             [mymoviePlayerController stop];
                             [mymoviePlayerController.view removeFromSuperview];
                             __block mymoviePlayerController = nil;

                         }];

    }
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios objective-c-blocks

1
推荐指数
1
解决办法
316
查看次数

iOS:如何正确获得电池电量

我试图获得正确的电池电量.但是这个值与iphone状态栏中的值不一样.

通过代码使用UIDevice:

[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];

[[UIDevice currentDevice] batteryLevel];
Run Code Online (Sandbox Code Playgroud)

请有人帮帮我!我需要正确的电池电量,就像在状态栏imdimatery.

ios ios5

1
推荐指数
1
解决办法
8150
查看次数

Swift 4 - 表达太复杂,无法在合理的时间内快速解决

我收到一个错误,这个表达太复杂了,无法在合理的时间内解决swift 4任何人都可以帮助我吗?

- AppDelegate.removeGIF(withURL: "images/" + self.currentUID + "/" + self.thisPostId + "." + self.currentGifExt)
Run Code Online (Sandbox Code Playgroud)

xcode ios swift swift4 xcode9

1
推荐指数
1
解决办法
999
查看次数