[帮助]将Obj-C转换为C# [英] [Help] convert Obj-C to C#

查看:88
本文介绍了[帮助]将Obj-C转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- (float) getVerticalOffset:(CGPoint)point1 point2:(CGPoint)point2 point3:(CGPoint)point3 point4:(CGPoint)point4 magnetLen:(float)length{
    float result = length;
    if (point1.x > point2.x){
        float t = point1.x; point1.x = point2.x; point2.x = t;
    }
    point1.x -= length;
    point2.x += length;
    if (point3.x > point4.x){
        float t = point3.x; point3.x = point4.x; point4.x = t;
    }
    if ((point1.x < point3.x && point3.x < point2.x)
        || (point1.x < point4.x && point4.x < point2.x)
        || (point3.x < point1.x && point1.x < point4.x)
        || (point3.x < point2.x && point2.x < point4.x)){
        if (fabs(point3.y-point1.y) < length){
            result = point3.y-point1.y;
        }
    }
    return result;
}

- (float) getHorizonOffset:(CGPoint)point1 point2:(CGPoint)point2 point3:(CGPoint)point3 point4:(CGPoint)point4 magnetLen:(float)length{
    float result = length;
    if (point1.y > point2.y){
        float t = point1.y; point1.y = point2.y; point2.y = t;
    }
    point1.y -= length;
    point2.y += length;
    if (point3.y > point4.y){
        float t = point3.y; point3.y = point4.y; point4.y = t;
    }
    if ((point1.y < point3.y && point3.y < point2.y)
        || (point1.y < point4.y && point4.y < point2.y)
        || (point3.y < point1.y && point1.y < point4.y)
        || (point3.y < point2.y && point2.y < point4.y)){
        if (fabs(point3.x-point1.x) < length){
            result = point3.x-point1.x;
        }
    }
    return result;
}

- (CGSize) magnetProccess:(CGRect)rect1 top:(bool)top bottom:(bool)bottom left:(bool)left right:(bool)right{
    float magnetLength = 20;
    CGRect parentRect = self.view.superview.frame;
    NSMutableArray* arrView = [delegate getAllMDIView];
    
    float minHorOffset = magnetLength, minVerOffset = magnetLength;
    NSInteger count = arrView.count;
    
    for (int k=0;k <= count;k ++){
        CGRect rect2;
        if (k < count){
            MovableViewCtr* view = arrView[k];
            if (view != self){
                rect2 = view.view.frame;
            }else{
                continue;
            }
        }else{
            rect2 = parentRect;
        }
        
        float arr1[4][2] = {{0, 0}, {rect1.size.width, 0}, {rect1.size.width, rect1.size.height}, {0, rect1.size.height}};
        float arr2[4][2] = {{0, 0}, {rect2.size.width, 0}, {rect2.size.width, rect2.size.height}, {0, rect2.size.height}};
        
        CGPoint basePoint1 = rect1.origin;
        CGPoint basePoint2 = rect2.origin;
        
        for (int i=0;i < 4;i ++){
            if ((!top && i == 0) || (!right && i == 1) || (!bottom && i == 2) || (!left && i == 3)){
                continue;
            }
            CGPoint point1 = CGPointMake(basePoint1.x+arr1[i][0], basePoint1.y+arr1[i][1]);
            CGPoint point2 = CGPointMake(basePoint1.x+arr1[(i+1)%4][0], basePoint1.y+arr1[(i+1)%4][1]);
            for (int j=0;j < 4;j ++){
                if (i%2 == j%2){
                    CGPoint point3 = CGPointMake(basePoint2.x+arr2[j][0], basePoint2.y+arr2[j][1]);
                    CGPoint point4 = CGPointMake(basePoint2.x+arr2[(j+1)%4][0], basePoint2.y+arr2[(j+1)%4][1]);
                    if (i%2 == 0){
                        float vOffset = [self getVerticalOffset:point1 point2:point2 point3:point3 point4:point4 magnetLen:magnetLength];
                        if (fabs(vOffset) < fabs(minVerOffset)){
                            minVerOffset = vOffset;
                        }
                    }else{
                        float hOffset = [self getHorizonOffset:point1 point2:point2 point3:point3 point4:point4 magnetLen:magnetLength];
                        if (fabs(hOffset) < fabs(minHorOffset)){
                            minHorOffset = hOffset;
                        }
                    }
                }
            }
        }
    }
    
    minHorOffset = minHorOffset!=magnetLength?minHorOffset:0;
    minVerOffset = minVerOffset!=magnetLength?minVerOffset:0;
    return CGSizeMake(minHorOffset, minVerOffset);
}



请帮我把这段代码转换成C#,tks


please help me convert this code to C#, tks

推荐答案

请看链接以下..



http://www.cocoabuilder.com/archive/cocoa/108318-converting-objective-to.html#108318



希望它有所帮助。
Please see link below..

http://www.cocoabuilder.com/archive/cocoa/108318-converting-objective-to.html#108318

Hope it helps.


NSFileManager * fileManager = [NSFileManager defaultManager];

NSURL * bundleURL = [[NSBundle mainBundle] bundleURL];

NSArray * contents = [fileManager contentsOfDirectoryAtURL:bundleURL

includingPropertiesForKeys:@ []

选项:NSDirectoryEnumerationSkipsHiddenFiles

错误:nil];



NSPredicate * predicate = [NSPredicate predicateWithFormat:@pathExtension =='png'];

for(NSURL * fileURL in [contents filteredArrayUsingPredicate:predicate]){

//枚举目录中的每个.png文件

}
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *bundleURL = [[NSBundle mainBundle] bundleURL];
NSArray *contents = [fileManager contentsOfDirectoryAtURL:bundleURL
includingPropertiesForKeys:@[]
options:NSDirectoryEnumerationSkipsHiddenFiles
error:nil];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"pathExtension == 'png'"];
for (NSURL *fileURL in [contents filteredArrayUsingPredicate:predicate]) {
// Enumerate each .png file in directory
}


这篇关于[帮助]将Obj-C转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆