【iOS】Realm build

Xcodeをバージョンアップしたときに、Realmのビルドしたバージョンとの違いが問題になる。
Module compiled with Swift 4.0 cannot be imported in Swift 4.0.3:


git clone https://github.com/realm/realm-cocoa
git submodule update --init --recursive
build.sh build

【iOS】文字の色変え(部分的に)

      //行間

        let textStyle = NSMutableParagraphStyle()

        textStyle.lineSpacing = LINE_H

        textStyle.paragraphSpacing = LINE_H // 改行時の行間スペース

       

        // FONT

        let _font_en:UIFont = UIFont(name:“HelveticaNeue-Light”, size:18)!;

        // set all style attributes

        let attributes_en: Dictionary = [NSParagraphStyleAttributeName: textStyle, NSFontAttributeName: _font_en]

        let attrText = NSMutableAttributedString(string: tx)

        attrText.addAttribute(NSForegroundColorAttributeName, value: UIColor.red, range: NSMakeRange(red_from,red_len))

        attrText.addAttribute(NSParagraphStyleAttributeName, value:textStyle, range:NSMakeRange(0, tx.characters.count))

        

        txAnswer.attributedText = attrText

        txAnswer.font=_font_en;

vvosc + swift

vvosc-ios

https://github.com/markcerqueira/vvosc-ios

 

・TARGETS > Build Setting > Architectures > Architectures

$(ARCHS_STANDARD_32_BIT) -> $(ARCHS_STANDARD) へ変更。

 

・ios simulatorと、ios deviceでそれぞれビルド。

 

・cd ~/Library/Developer/Xcode/DerivedData/VVOSC-xxxxxxxxx/Build/Product/

 

・下記実行

lipo -create  Debug-iphoneos/libVVOSC.a   Debug-iphonesimulator/libVVOSC.a -output  libVVOSC.a

 

・includeフォルダと、上のlibVVOSC.aをプロジェクトに追加。

・TARGETS > Build Settings >Linking >Other Link Flag に -ObjC と、-all_loadを追加。

・Swift Compiler -Code Generation > Objective-C Bridging Header に、bh.hを追加。

#ifndef bh_h

#define bh_h

#import "../VVOSC/include/VVOSC.h"

#endif /* bh_h */

 

・swift ソースコード

var out = OSCOutPort(address: "192.168.111.150", andPort: 8888)
var msg = OSCMessage.createWithAddress("/dev/acc") as! OSCMessage
msg.addInt(2);
msg.addFloat(1.0123);
out.sendThisMessage( msg )

 

 

【OF/iOS】Customize AppDelegate.

・Viewを重ねる方法

・OFのViewの背景を透過する。

    ofxiOSSetGLViewTransparent(true);

 

main.m

#include "ofMain.h"
#include "ofApp.h"

int main(){
    
    ofAppiOSWindow * window = new ofAppiOSWindow();
    window->enableRetina();
    
    ofSetupOpenGL(ofPtr<ofAppBaseWindow>(window), 1024,768, OF_FULLSCREEN);
    window->startAppWithDelegate("MyAppDelegate");
}

 

MyAppDelegate.mm

#import "MyAppDelegate.h"

@implementation MyAppDelegate

@synthesize vc;
AVCaptureVideoPreviewLayer* previewLayer;
UIView* cameraView;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    
    [super applicationDidFinishLaunching:application];
    
    self.vc = [[RootViewController alloc] init];
    [self.window setRootViewController: self.vc];
    
    setupCameraPreview();
    [self.vc.view addSubview: cameraView];

    AppViewController* app = [[AppViewController alloc] init];
    [self.vc.view addSubview: app.view];

    
    return YES;
}

- (void) dealloc {
    self.vc = nil;
    [super dealloc];
}



void setupCameraPreview()
{
    AVCaptureSession *session = [AVCaptureSession new];
//    [session setSessionPreset:AVCaptureSessionPreset1920x1080];
    [session setSessionPreset:AVCaptureSessionPreset1280x720];
    
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
    
    if ([session canAddInput:deviceInput]){
        [session addInput:deviceInput];
    }
    
    previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
    [previewLayer setBackgroundColor:[[UIColor blackColor] CGColor]];
    [previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    
    cameraView = [[UIView alloc]initWithFrame: CGRectMake(0,0,640/2,1136/2)];
    cameraView.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.f];
    
    CALayer *rootLayer = [cameraView layer];
    [rootLayer setMasksToBounds:YES];
    [previewLayer setFrame:[rootLayer bounds]];
    [rootLayer addSublayer:previewLayer];
    [session startRunning];
   
}
@end

 

MyAppDelegate.h

#import "ofxiOSAppDelegate.h"

#import <AVFoundation/AVFoundation.h>
#import "AppViewController.h"
#import "RootViewController.h"

@interface MyAppDelegate : ofxiOSAppDelegate {

}

@property (nonatomic, retain) RootViewController* vc;

 

RootViewController.h

@interface RootViewController : UIViewController

@end

 

RootViewController.mm

#import <Foundation/Foundation.h>
#import "RootViewController.h"

@implementation RootViewController

- (BOOL)shouldAutorotate {

    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeRight;
}
@end

 

AppViewController.mm

#import "AppViewController.h"
#import "ofApp.h"

@implementation AppViewController

- (id)init {

   self = [super initWithFrame:[UIScreen mainScreen].bounds app: new ofApp()];
    if(self != nil) {

    }
    return self;
}

@end

 

AppViewController.h

#import "ofxiOSViewController.h"

@interface AppViewController : ofxiOSViewController

@end

ofApp.mm

//--------------------------------------------------------------
void ofApp::setup(){
 
    ofBackground(0,0,0,0);
    ofSetOrientation(OF_ORIENTATION_DEFAULT);
    
    ofxiOSSendGLViewToFront();
    ofxiOSSetGLViewTransparent(true);
//    ofxiOSSetGLViewUserInteraction(false);
    
    ofEnableAlphaBlending();
    camera.setPosition(0,0,0);
    camera.setupPerspective();
    camera.setVFlip(false);
    camera.setFarClip(5000);
    //camera.disableMouseInput();
}


//--------------------------------------------------------------
void ofApp::update() {
}

//--------------------------------------------------------------
void ofApp::draw() {

    camera.begin();

    ofSetColor(255, 0, 0,100);
    ofSetConeResolution(32, 16);
    ofDrawCone(0, 0, 0, 25, 50);

    camera.end();
}

//--------------------------------------------------------------
void ofApp::exit(){
    
}

ofApp.h

class ofApp : public ofxiOSApp {

    public:
        void setup();
        void update();
        void draw();
        void exit();
	
        void touchDown(ofTouchEventArgs & touch);
        void touchMoved(ofTouchEventArgs & touch);
        void touchUp(ofTouchEventArgs & touch);
        void touchDoubleTap(ofTouchEventArgs & touch);
        void touchCancelled(ofTouchEventArgs & touch);

}

 

 

 

 

 

【OF+iOS】隠面処理が有効にならない

main.mmに下記を追加する。

int main(){

        ofAppiPhoneWindow * iOSWindow = newofAppiPhoneWindow();

        iOSWindow->enableDepthBuffer();

        ofSetupOpenGL(iOSWindow, 1024,768,OF_FULLSCREEN);// <——– setup the GL context

  ofRunApp(newofApp());

}

draw()等で、下記で囲った中にを記載する。

ofEnableDepthTest();

….

ofBoxPrimitive box;

box.draw();

….

ofDisableDepthTest();

これでOK